Matplotlib(二)概述

之前的文章是通过与Matlab比较说明Matplotlib的功能。那么,Matplotlib都可以做些什么事情呢?

Matplotlib组成

Matplotlib基本类有很多,常见的有:

  • matplotlib
  • matplotlib.animation
  • matplotlib.artist
  • matplotlib.axes
  • matplotlib.axis
  • matplotlib.dates
  • matplotlib.figure
  • matplotlib.image
  • matplotlib.legend
  • matplotlib.lines
  • matplotlib.markers
  • matplotlib.mathtext
  • matplotlib.pyplot
  • matplotlib.quiver
  • matplotlib.table
  • matplotlib.text

涵盖了大量我们作图物件,如箭头、公式、文本点、线的定义等等。其中,有一非常重要的类:pyplot,这也是为什么我们在画图之前都需要加上这个语句import matplotlib.pyplot as plt的原因。通过plt这个类使得我们能绘制一切预定好的一些组件:如lengend、点、线、坐标轴、文本等等。具体的,plt可以绘制特定属性的空间,如:

  • xlabel Set the label for the x-axis.
  • xlim Get or set the x limits of the current axes.
  • xscale Set the x-axis scale.
  • xticks Get or set the current tick locations and labels of the x-axis.
  • ylabel Set the label for the y-axis.
  • ylim Get or set the y-limits of the current axes.
  • yscale Set the y-axis scale.
  • yticks Get or set the current tick locations and labels of the y-axis.
  • figtext Add text to figure.
  • figure Create a new figure, or activate an existing figure.
  • axis Convenience method to get or set some axis properties.
  • axes Add an axes to the current figure and make it the current axes.
  • imread Read an image from a file into an array.
  • imsave Save an array as an image file.
  • imshow Display data as an image, i.e., on a 2D regular raster.
  • annotate Annotate the point xy with text text.
  • arrow Add an arrow to the axes.
  • autoscale Autoscale the axis view to the data (toggle).
  • axes Add an axes to the current figure and make it the current axes.

pyplot画出我们想要的东西

举个简单的例子,随便举个例子,在matplotlib的官方手册上可以很轻松的查阅使用说明。
在这里插入图片描述
一般来说,这些东西都会画在figure中,也就是那个每次弹出来的窗口中。包括这个窗口都是由plt控制的,我们首先创建一个名字为apple的窗口:

plt.figure('apple')

运行之后就会弹出下面的窗口:
在这里插入图片描述
这个figure是可以通过参数进行设置的,包括其大小,名称(也就是我们刚刚设置的apple)。只不过有默认行为表现出的默认行为罢了。OK!接下来,我们通过调用plt.axes画一个坐标轴!这次我们什么参数都不设置,结果如下:
在这里插入图片描述
这就是一个什么属性都不设置的:默认坐标坐标轴,从图上可以看出其默认行为:

  • 默认将是一个笛卡尔xy轴;
  • 刻度范围是0.0-1.0;
  • 绘制在整个figure的正中央;
  • 留有合适的空白;
  • 默认是白色背景,等等。

我们可以更改什么内容呢?可以通过官方手册查询
在这里插入图片描述
那么我们更改其位置看看:

plt.figure('apple')
plt.axes((0.5,0.5,0.25,0.25))

在这里插入图片描述
随着程序的运行,可能需要改变控件的属性,这时候就需要用到每次调用的返回值,如这里的plt.axe
在这里插入图片描述

plt.figure('apple')
ax=plt.axes((0.5,0.5,0.25,0.25))
ax.set_position((0.1,0.1,0.25,0.25))

可以看出,我们通过返回的一个ax对象,得以继续修改已经画出来的东西,就本例就重新地修改了位置。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值