我正在尝试制作一个情节,其中各种子情节都共享一个类似于此答案的颜色条。我遇到的问题是,在我的脚本中,我正在调用一个函数,该函数创建QuadMesh
(生成自ax.pcolormesh
)实例并返回与其关联的Figure
和实例。Axes
有没有办法从 Axes 实例(或 Figure 实例)获取 QuadMesh 实例的句柄?
import matplotlib.pyplot as plt
import numpy as np
def foo(subplot):
data = np.random.random((100,100))
x,y = np.meshgrid(np.arange(101),np.arange(101))
fig = plt.gcf()
ax = fig.add_subplot(subplot)
quadmesh = ax.pcolormesh(x,y,data)
return fig,ax
fig = plt.figure()
f,a = foo(221)
f,a = foo(222)
f,a = foo(223)
f,a = foo(224)
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85,0.15,0.05,0.7])
#fig.colorbar(magic_get_quadmesh,cax=cbar_ax)
plt.show()