API概述¶
也见 API更改 .
使用模式¶
下面我们将介绍几种使用matplotlib进行绘图的常见方法。
PyPoPAPI¶
matplotlib.pyplot 是命令样式函数的集合,使matplotlib像matlab一样工作。每个Pyplot函数对图形进行一些更改:例如,创建图形、在图形中创建绘图区域、在绘图区域中绘制一些线、用标签装饰绘图等。
pyplot 主要用于交互式绘图和程序化绘图生成的简单案例。
进一步阅读:
- 这个
matplotlib.pyplot函数引用 - PyPror教程
- Pyplot examples
面向对象的API¶
Matplotlib的核心是面向对象的。如果需要对绘图进行更多的控制和自定义,建议直接使用对象。
在许多情况下,您将创建一个 Figure 一个或多个 Axes 使用 pyplot.subplots 从那时起,只在这些物体上工作。但是,也可以创建 Figure 显式(例如,在GUI应用程序中包含它们时)。
进一步阅读:
matplotlib.axes.Axes和matplotlib.figure.Figure有关绘图功能的概述。- 大部分的 examples 使用面向对象的方法(Pyplot部分除外)
Pylab API(未批准)¶
警告
由于大量导入到全局命名空间可能会导致意外行为,因此强烈建议不要使用pylab , 而是使用 matplotlib.pyplot 。
pylab 是一个包含 matplotlib.pyplot , numpy , numpy.fft , numpy.linalg , numpy.random ,以及一些附加函数,都在一个名称空间中。它最初的目的是通过将所有函数导入全局名称空间来模拟类似MATLAB的工作方式。现在这种款式被认为是不好的。
模块¶
Matplotlib由以下子模块组成:
matplotlibmatplotlib.afmmatplotlib.animationmatplotlib.artistmatplotlib.axesmatplotlib.axismatplotlib.backend_basesmatplotlib.backend_managersmatplotlib.backend_toolsmatplotlib.backendsmatplotlib.beziermatplotlib.blocking_inputmatplotlib.categorymatplotlib.cbookmatplotlib.cmmatplotlib.collectionsmatplotlib.colorbarmatplotlib.colorsmatplotlib.containermatplotlib.contourmatplotlib.datesmatplotlib.dvireadmatplotlib.figurematplotlib.font_managermatplotlib.fontconfig_patternmatplotlib.gridspecmatplotlib.imagematplotlib.legendmatplotlib.legend_handlermatplotlib.linesmatplotlib.markersmatplotlib.mathtextmatplotlib.mlabmatplotlib.offsetboxmatplotlib.patchesmatplotlib.pathmatplotlib.patheffectsmatplotlib.pyplotmatplotlib.projectionsmatplotlib.projections.polarmatplotlib.quivermatplotlib.rcsetupmatplotlib.sankeymatplotlib.scalematplotlib.sphinxext.plot_directivematplotlib.spinesmatplotlib.stylematplotlib.tablematplotlib.testingmatplotlib.textmatplotlib.texmanagermatplotlib.textpathmatplotlib.tickermatplotlib.tight_layoutmatplotlib.transformsmatplotlib.trimatplotlib.type1fontmatplotlib.unitsmatplotlib.widgets