[英]Ticks plotted with an offset in colorbar
Problem: I am plotting the colorbar using Matplotlib, but these ticks are set at 0.0, 0.1.. to 0.5. 问题:我正在使用Matplotlib绘制颜色条,但是这些刻度设置为0.0、0.1 ..到0.5。
I wanted to get more intervals in between, but that leads to me having this following problem : Irregularly spaced tick labels. 我想在它们之间获得更多的间隔,但是这导致我遇到以下问题:不规则的刻度标签。
In this picture, I have marked in red the offset in the ticks. 在这张照片中,我在刻度中用红色标记了偏移量。
Code: 码:
plt.pcolor(data_mod, vmin = 0.01, vmax = 0.5, cmap=cmap)
cb = plt.colorbar(extend='both')
cb.set_label('CPRESS', fontsize=7, labelpad=-10, y=1.05, rotation=0)
tick_locator = ticker.MaxNLocator(nbins = 10)
cb.locator = tick_locator
cb.update_ticks()
plt.imshow(data_mod)
What could I be doing wrong? 我可能做错了什么? Would it be possible to make the ticks just on top (starting) of the colors?
是否可以将刻度线放在颜色的顶部(开始)?
I could imagine you want to fix the boundaries of colors shown on the plot and in the colorbar to the values of numpy.linspace(0,.5,11)
. 我可以想象您想将绘图和颜色
numpy.linspace(0,.5,11)
显示的颜色的边界固定为numpy.linspace(0,.5,11)
。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors
cmap = plt.get_cmap("jet",11)
data = np.random.rand(10,10)/2.
norm=matplotlib.colors.BoundaryNorm(np.linspace(0,0.5,11),11)
plt.pcolor(data, norm=norm, cmap=cmap)
cb = plt.colorbar(extend='both', ticks=np.linspace(0,0.5,11))
cb.set_label('CPRESS', fontsize=7, labelpad=-10, y=1.05, rotation=0)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.