正文
2005
-
01
-
07
983.958
2005
-
01
-
10
993.879
接下来,就可以开始画图了,我们需要导入
matplotlib.pyplot
【2】,然后通过设置
set_xlabel()
和
set_xlabel()
为x轴和y轴添加标签。
import matplotlib.pyplot as plt
ax = df.plot(color='')
ax.set_xlabel('trade_date')
ax.set_ylabel('399300.SZ close')
plt.show()
matplotlib库中有很多内置图表样式可以选择,通过打印
plt.style.available
查看具体都有哪些选项,应用的时候直接调用
plt.style.use('fivethirtyeight')
即可。
print(plt.style.available)
['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']
plt.style.use('fivethirtyeight')
ax1 = df.plot()
ax1.set_title('FiveThirtyEight Style')
plt.show()
02
设置更多细节
上面画出的是一个很简单的折线图,其实可以在plot()里面通过设置不同参数的值,为图添加更多细节,使其更美观、清晰。
figsize(width, height)
设置图的大小,
linewidth
设置线的宽度,
fontsize
设置字体大小。然后,调用
set_title()
方法设置标题。
ax = df.plot(color='blue', figsize=(8, 3), linewidth=2, fontsize=6)
ax.set_title('399300.SZ close from 2005-01-04 to 2019-07-04'