1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python colorbar刻度_python-如何添加Matplotlib Colorbar刻度

python colorbar刻度_python-如何添加Matplotlib Colorbar刻度

时间:2024-04-27 05:00:29

相关推荐

python colorbar刻度_python-如何添加Matplotlib Colorbar刻度

关于堆栈溢出有很多matplotlib colorbar问题,但是为了解决我的问题,我无法理解它们.

如何在颜色栏上设置yticklabel?

这是一些示例代码:

from pylab import *

from matplotlib.colors import LogNorm

import matplotlib.pyplot as plt

f = np.arange(0,101) # frequency

t = np.arange(11,245) # time

z = 20*np.sin(f**0.56)+22 # function

z = np.reshape(z,(1,max(f.shape))) # reshape the function

Z = z*np.ones((max(t.shape),1)) # make the single vector to a mxn matrix

T, F = meshgrid(f,t)

fig = plt.figure()

ax = fig.add_subplot(111)

plt.pcolor(F,T,Z, norm=LogNorm(vmin=z.min(),vmax=z.max()))

plt.xlim((t.min(),t.max()))

mn=int(np.floor(Z.min())) # colorbar min value

mx=int(np.ceil(Z.max())) # colorbar max value

md=(mx-mn)/2 # colorbar midpoint value

cbar=plt.colorbar() # the mystery step ???????????

cbar.set_yticklabels([mn,md,mx]) # add the labels

plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。