Python for Data Science - Defining elements of a plot

Chapter 4 - Practical Data Visualization

Segment 2 - Defining elements of a plot

import numpy as np
from numpy.random import randn
import pandas as pd
from pandas import Series, DataFrame

import matplotlib.pyplot as plt
from matplotlib import rcParams
%matplotlib inline
rcParams['figure.figsize']=5,4

Defining axes, ticks, and grids

x = range(1,10)
y = [1,2,3,4,0,4,3,2,1]

fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])

ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716e09d240>]

Python for Data Science - Defining elements of a plot

fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])

ax.set_xlim([1,9])
ax.set_ylim([0,5])

ax.set_xticks([0,1,2,4,5,6,8,9,10])
ax.set_yticks([0,1,2,3,4,5])

ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d98a8d0>]

Python for Data Science - Defining elements of a plot

fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])

ax.set_xlim([1,9])
ax.set_ylim([0,5])

ax.grid()
ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d9a3be0>]

Python for Data Science - Defining elements of a plot

Generating multiple plots in one figure with subplots

fig = plt.figure()
fig,(ax1, ax2) = plt.subplots(1,2)

ax1.plot(x)
ax2.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d873f98>]




<Figure size 360x288 with 0 Axes>

Python for Data Science - Defining elements of a plot

上一篇:Elements in iteration expect to have 'v-bind:key' directives


下一篇:面试题-输出所有页面宽度和高度大于 50 像素的节点