最近看到一个讲Matplotlib的英文教程写的很高明,兼收并蓄,简单易懂,特意翻译过来,与君共享。原网址在:http://cs231n.github.io/python-numpy-tutorial/#matplotlib 。
Matplotlib(https://matplotlib.org/)是一个用来绘图的python库,它的matplotlib.pyplot
模块提供了一个与MATLAB非常类似的绘图系统。
绘图(Plotting)
matplotlib中最重要的函数就是plot
,它可以绘制二维图像,例子如下:
import numpy as np
import matplotlib.pyplot as plt
# Compute the x and y coordinates for points on a sine curve
x = np.arange(0, 3 * np.pi, 0.1)
y = np.sin(x)
# Plot the points using matplotlib
plt.plot(x, y)
# 注意,必须调用plt.show(),不然图像不会显示出来
plt.show()
运行上述代码的结果如下: