学习机器视觉在编写代码的时候发现对画图展示数据不是很懂,所以就去官方文档上去查看有关matplotlib的技术文档。
首先看模块里面包含的模块:
Modules include:
:mod:`matplotlib.axes`
defines the :class:`~matplotlib.axes.Axes` class. Most pylab
commands are wrappers for :class:`~matplotlib.axes.Axes`
methods. The axes module is the highest level of OO access to
the library.
:mod:`matplotlib.figure`
defines the :class:`~matplotlib.figure.Figure` class.
:mod:`matplotlib.artist`
defines the :class:`~matplotlib.artist.Artist` base class for
all classes that draw things.
:mod:`matplotlib.lines`
defines the :class:`~matplotlib.lines.Line2D` class for
drawing lines and markers
:mod:`matplotlib.patches`
defines classes for drawing polygons
:mod:`matplotlib.text`
defines the :class:`~matplotlib.text.Text`,
:class:`~matplotlib.text.TextWithDash`, and
:class:`~matplotlib.text.Annotate` classes
:mod:`matplotlib.image`
defines the :class:`~matplotlib.image.AxesImage` and
:class:`~matplotlib.image.FigureImage` classes
:mod:`matplotlib.collections`
classes for efficient drawing of groups of lines or polygons
:mod:`matplotlib.colors`
classes for interpreting color specifications and for making
colormaps
:mod:`matplotlib.cm`
colormaps and the :class:`~matplotlib.image.ScalarMappable`
mixin class for providing color mapping functionality to other
classes
:mod:`matplotlib.ticker`
classes for calculating tick mark locations and for formatting
tick labels
:mod:`matplotlib.backends`
a subpackage with modules for various gui libraries and output
formats
总共有以上几个模块!
图片要素分类
引用官方文档的一句话:the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets
the coordinate system.图片的要素有这样几个分类:
轴(Axis)
轴的初始化函数如文档所示:
参数需要一个axes的对象作为参数来进行传参,对于生成一个axes的对象从文档中我们可以找到刻度(Tick)
线2-D(Line2D)
4.文本(text)
5.多边形等等
pyplot.plot()理解
我们在用python画图的时候避免不了就是使用plot函数,plot函数究竟是怎样的一个函数?
我们看下相关文档,贴图如下
文档上说就是将Y与X作为线和/或标记,返回的对象是一条线。
也就是说我们调用这个函数,相当于对plt的对象调用了一个方法,但是如果我们没有调用plot.show()函数,我们的图像不会画出来,我们调用了plot函数时,系统默认帮我们生成了一个对象,这个对象其实就是一个figure对象,然后我们调用了plot函数,其实就是返回了一条曲线画在了figure,如果我们最后不调用show()函数,那么对于代码来说,我们并没有生成一个曲线图片。
对于subplot()想说的是,如果我们调用了show()函数,那么系统就会为我们生成一个figure画板,来供我们画曲线。
for i in range(4):
plt.subplot(2,2,i+1)
plt.show()
像上面的代码的话,其实是每次生成一个figure,然后在上面画上单词循环里面所有的曲线,首先会画出一个右上角的坐标,然后关闭图片则会弹出第二个左上角的坐标,然后关闭依次是左下角,右下角。总结来说,当程序运行到matplotlib.show()函数的时候,程序会处于中断状态,当你结束show()函数进程,关闭plot的图片时候,程序继续执行。
应该从面向对象的角度理解matplotlib库。