3.4 Pandas画图
- 目标:
- DataFrame的画图函数
- 了解Series的画图函数
- 内容预览:
- 3.4.1 pandas.DataFrame.plot()
- 3.4.2 pandas.Series.plot()
3.4.1 pandas.DataFrame.plot()
-
DataFrame.plot(x=None, y=None, kind=‘line’)
- x : label or position, default None
- y : label, position or list of label, positions, default None
- Allows plotting of one column versus another
- kind : str
- ‘line’ : line plot (default)
- ‘bar’ : vertical bar plot
- ‘barth’ : horizontal bar plot
- ‘hist’ : histogram
- ‘pie’ : pie plot
- ‘scatter’ : scatter plot
-
df.plot()无法显示中文的解决办法:
import matplotlib
matplotlib.rcParams['font.sans-serif']=['SimSun'] #用来正常显示中文标签
matplotlib.rcParams['axes.unicode_minus']=False #用来正常显示负号
data.plot(x='change', y='amount', kind='scatter')
<matplotlib.axes._subplots.AxesSubplot at 0x176fac31e08>
data.plot(x='vol', y='amount', kind='scatter')
<matplotlib.axes._subplots.AxesSubplot at 0x176fb0e2448>
data.plot(x='high', y='low', kind='scatter')
<matplotlib.axes._subplots.AxesSubplot at 0x176fac06b88>
3.4.2 pandas.Series.plot()
data['close'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x176fb0d5b08>