往往我们可能希望创建一个绘图对象,然后对其进行修改,或者作为函数参数。
那么plt.plot 无法满足, 而采用Axes 对象,可以创建和传递绘图对象。
Axes 对象是subplot 底下的,如果我们只需要一张图,那么可以在subplot 中设置图片数为 1,1 。
例子:
def _profile(ax, x, y):
ln, = ax.plot(x, y)
# return the Artist created
return ln
def profile_matrix(n, m):
fig, ax_array = plt.subplots(n, m, sharex=True, sharey=True)
for ax in np.ravel(ax_array):
_profile(ax, np.arange(50), np.random.rand(50))
profile_matrix(1, 1)
结果如下: