matplotlib是一个数据可视化模块,可以用它完成图像处理,制表,3D图,图像处理等。
导入matplotlib和其他模块
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
ax1.set_title("折线图")
ax2.set_title("柱形图")
创建
x1 = np.arange(1,6)
y1 = np.array([8,7,9,6,5])
ax1.plot(x1,y1)
x2 = np.arange(5)
y2 = np.array([6,5,7,8,9])
width = 0.6
ax2.bar(x2,y2,width=width)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
ax1.set_title("折线图")
ax2.set_title("柱形图")
x1 = np.arange(1, 6)
y1 = np.array([8, 7, 9, 6, 5])
ax1.plot(x1, y1)
x2 = np.arange(5)
y2 = np.array([6, 5, 7, 8, 9])
width = 0.6
ax2.bar(x2, y2, width=width)
plt.show()
运行结果