暑假准备准备做个matplotlib绘图专栏,今天从创建画布开始
首先要创建一张画布:
import matplotlib.pyplot as plt
fig = plt.figure()
这行代码其实没什么可解释的,言外之意就是“我要开始画图了”
接着创建子图:
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,4)
这个意识就是创建一个2行X2列的图,fig.add_subplot(2,2,2)第三个值代表第几张图,我特意设置了1,2,4是为了更直观的展现。
接下来展示一下:
plt.show()
接着我们随便出个折线图试试:
ax3.plot([1.5,8,3.5,-1,9])
完整代码:
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,4)
ax3.plot([1.5,8,3.5,-1,9])
plt.show()