matplotlib是python最著名的绘图库,主要用于二维作图,也可以进行简单的三维作图,
简单例子如下,环境和上一篇博客环境一样:
import numpy as npimport matplotlib.pyplot as pltx = np.linspace(0, 10, 1000)y = np.sin(x) + 1z = np.cos(x**2) + 1plt.figure(figsize=(8, 4))plt.plot(x, y, label='$\sin x+1$', color='red', linewidth=2)plt.plot(x, z, 'b--', label='$\cos x^2+1$')plt.xlabel('Time(s)')plt.ylabel('Volt')plt.title('A simple example')plt.ylim(0, 2.2)plt.legend()plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(x) + 1
z = np.cos(x**2) + 1
plt.figure(figsize=(8, 4))
plt.plot(x, y, label='$\sin x+1$', color='red', linewidth=2)
plt.plot(x, z, 'b--', label='$\cos x^2+1$')
plt.xlabel('Time(s)')
plt.ylabel('Volt')
plt.title('A simple example')
plt.ylim(0, 2.2)
plt.legend()
plt.show()
所画的图形如下: