【发布时间】:2017-02-22 12:33:14
【问题描述】:
我想做的很简单:对于使用plt.subplots() 创建的绘图,我想显示一个彩条。
所以,我就是这样做的:
def plotVF(self, u, v):
m = np.sqrt(np.power(u, 2) + np.power(v, 2))
xrange = np.linspace(0, u.shape[1], u.shape[1]);
yrange = np.linspace(0, u.shape[0], u.shape[0]);
x, y = np.meshgrid(xrange, yrange)
mag = np.hypot(u, v)
scale = 1
lw = scale * mag / mag.max()
f, ax = plt.subplots()
h = ax.streamplot(x, y, u, v, color=mag, linewidth=lw, density=3, arrowsize=1, norm=plt.Normalize(0, 70))
ax.set_xlim(0, u.shape[1])
ax.set_ylim(0, u.shape[0])
ax.set_xticks([])
ax.set_yticks([])
cbar = f.colorbar(h, ax=ax)
cbar.ax.tick_params(labelsize=5)
plt.show()
根据docs 中显示的内容。 但是,我一直收到:
AttributeError: 'StreamplotSet' object has no attribute 'autoscale_None'
这个例子只有一个情节,但我会有不止一个,这就是为什么我不直接使用plt.colorbar().
【问题讨论】:
标签: python matplotlib colorbar