matplotlib
的安装在之前的博客里有提到,可以去找找看
折线图
在同一张图中显示多个线条是因为hold
属性是默认打开的,将属性关闭那么新的绘制将把之前的线条覆盖。
interactive
是打开交互模式,随时可以观测线条的变化。
Adding a grid
Handling axes
默认坐标轴自适应,可以限制显示方式。
还有这几种方式控制坐标轴的变化:
plt.axis([xmin, xmax, ymin, ymax])
plt.axis(xmin=NNN, ymax=NNN)
Adding labels
Adding a title
Adding a legend
可以通过参数loc
修改图标位置,0-10表示不一样的位置。还可以通过,loc=(0,1)
表示左上角,(0.5,0.5)表示中间。当然,也可以利用loc='best'
自适应。
A complete example
Saving plots to a file
Configuring through the Python code
Selecting backend from code
Control colors
Specifying styles in multiline plots
Control line styles
Control marker styles
Finer control with keyword arguments
Handling X and Y ticks
Plot types
Histogram charts
By default, hist() uses a bin value of 10 (so only ten categories, or bars, are computed), but we can customize it, either by passing an additional parameter, for example, in hist(y, <bins>), or using the bin keyword argument as hist(y, bin=<bins>).