我有以下几行代码来生成热图(pcolormesh
)。
import matplotlib.pyplot as plt
import numpy as np
vals = np.linspace(-np.pi/2, np.pi/2, 101)
x, y = np.meshgrid(vals, vals)
z = np.abs(np.sinc(x) * np.sinc(y))
xDeg = np.rad2deg(x)
yDeg = np.rad2deg(y)
plt.pcolormesh(xDeg, yDeg, z, cmap = 'jet', vmin = 0, vmax = 1)
plt.colorbar()
plt.axis([-90, 90, -90, 90])
ticks = np.linspace(-90, 90, 13)
plt.xticks(ticks)
plt.yticks(ticks)
print np.mean(z) # 0.186225110029
print np.sqrt(np.mean(z**2)) # 0.295710882276
plt.show()
它产生此图像:
我想放置:
有输入吗?
最佳答案
这比预期的容易。我没有意识到Colorbar在plt.colorbar().ax
中具有可绘制的轴
cb = plt.colorbar()
cb.ax.plot(0.5, mean, 'w.') # my data is between 0 and 1
cb.ax.plot([0, 1], [rms]*2, 'w') # my data is between 0 and 1
# Note: would need to scale mean/rms to be between 0 and 1
看起来x轴是(0,1),y轴(dataMin,dataMax)(0,1)。
关于python - 在matplotlib中的颜色栏中添加标记或线条,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42446066/