python第三方库matplotlib官网英文文档学习兼翻译

目录

 

一.用户指南(Usage Guide)

1.1 了解一张图

1.2 作为需要画图的数据的输入方式(Types of inputs to plotting functions)

1.3 matplotlib,pyplot,pylab之间是什么关系(Matplotlib, pyplot and pylab: how are they related?)


一.用户指南(Usage Guide)

1.1 了解一张图

python第三方库matplotlib官网英文文档学习兼翻译

什么是axe,axis,figure,figure是指画板,axes指画纸,axis是指画纸的边缘,以此类推到上图。

下面用代码解释一下:

import matplotlib.pyplot as plt
fig=plt.figure()
fig.suptitle('No axes on this figure')
fig,ax_lst=plt.subplots(2,2)
plt.show()

出图:

python第三方库matplotlib官网英文文档学习兼翻译

python第三方库matplotlib官网英文文档学习兼翻译

一个figure中可以包含很多axes(第二张图),也可以不包含axes(第一张图),一个axes中包括2个axis(三维图中包含3个axis)

1.2 作为需要画图的数据的输入方式(Types of inputs to plotting functions

可以使用np.array或者np.ma.masked_array作为输入,也可以用类似array的输入,比如pandas和np.matrix,但是这个可能无法正常工作,所以最好转换成np.array

python第三方库matplotlib官网英文文档学习兼翻译

1.3 matplotlib,pyplot,pylab之间是什么关系(Matplotlib, pyplot and pylab: how are they related?)

matplotlib是一个完整的包,pyplot是其中一个模块,pylab是matplotlib下的一个子包(注:pylab最好不再使用)

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2, 100)#在指定的间隔内返回均匀间隔的数字
plt.plot(x, x, label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')
plt.xlabel('x label')
plt.ylabel('y label')
plt.title("Simple Plot")
plt.legend()
plt.show()
出图:

python第三方库matplotlib官网英文文档学习兼翻译