官网:https://matplotlib.org/contents.html
matplotlib是一个Python的会图库,以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形,它能够输出的图形包括折线图、散点图,直方图等。在数据可视化方面,matplotlib拥有数量众多的忠实用户,其强悍的绘图能力能够帮助我们对数据形成非常清晰直观的认识,下面我们来简单展示一下matplotlib的能力。
%matplotlib inline import numpy as np #激活matplotlib import matplotlib.pyplot as plt #下面生成一个从-20到20,元素数为10的等差数列 x = np.linspace(-20,20,10) #再令y = x^3 +2x^2 + 6x + 5 y = x**3 + 2*x**2 + 6*x + 5 #下面画出这条函数的曲线 plt.plot(x,y, marker = "o")开头的%matplotlib inline表示jupyter Botebook进行内置实时的绘图。
否则在最后一行加入plt.show()进行显示,这样绘图才能显示出来。
还有一些比较重要的模块:
pyplot 模块Provides a MATLAB-like plotting framework.
pylab combines pyplot with numpy into a single namespace. This is convenient for interactive work, but for programming it is recommended that the namespaces be kept separate, e.g.:
import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 5, 0.1); y = np.sin(x) plt.plot(x, y) cm 模块Builtin colormaps, colormap handling utilities, and the ScalarMappable mixin.
gridspec 模块gridspec is a module which specifies the location of the subplot in the figure.