【发布时间】:2015-12-18 22:21:35
【问题描述】:
所以我需要使用“z 轴”值创建带有设定点和颜色的 2D 图,就像您看到的那样,这不是问题。
我现在需要的是在右侧添加具有全色阶的颜色条。我试过这样做,但没有效果:
x=numpy.loadtxt('h2o.dat',unpack=True)
shiftposition(x,-45.1*prze,266.67)
vmin=x[0].min()
vmax=x[0].max()
dv=vmax-vmin
cmap = cm.jet
colors = matplotlib.colors.Normalize(vmin+0.0, vmax+0.0)
fig, ax = plt.subplots()
plt.arrow(-46,345, 100*math.sin(math.radians(40)), 100*math.cos(math.radians(40)), head_width=20, head_length=20, fc='r', ec='r',color='r')
plt.arrow(25,163, 100*math.sin(math.radians(125)), 100*math.cos(math.radians(125)), head_width=20, head_length=20, fc='r', ec='r',color='r')
plt.arrow(-280,342, 100*math.sin(math.radians(-55)), 100*math.cos(math.radians(-55)), head_width=20, head_length=20, fc='b', ec='b',color='b')
plt.arrow(-233,120, 100*math.sin(math.radians(-140)), 100*math.cos(math.radians(-140)), head_width=20, head_length=20, fc='b', ec='b',color='b')
plt.scatter(-20*prze,242.8,marker='+',s=50,color='k')
ax.scatter(x[1],x[2],marker='^',color=cm.jet((x[0]-vmin)/dv,1),s=50,zorder=3)
cax = matplotlib.colorbar.ColorbarBase(ax, cmap=cmap,norm=colors,orientation='vertical',spacing='uniform',ticklocation='auto')
ax.set_xlim(-500,250)
ax.set_ylim(-200,550)
ax.invert_xaxis()
plt.show()
我做错了什么?
【问题讨论】:
-
我没有看到
plt.colorbar函数,matplotlib.org/examples/pylab_examples/… -
我觉得你没有将颜色条添加到你的情节中。
fig.colorbar(args) -
如果我理解正确 plt.colorbar 是用于 ScalarMappable 的图像和等高线图,在我的情况下它没有用......并且 colorbar.ColorbarBase 应该更通用,但它不适用于我和我不知道为什么。
标签: python matplotlib