【发布时间】:2013-11-19 18:31:07
【问题描述】:
我目前正在尝试在颜色栏中设置次要刻度,但根本无法使其工作。我尝试了 3 种方法(请参见下面的代码),但它们似乎都不起作用。彩条中真的可以有小刻度吗?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.ticker import FixedLocator, FormatStrFormatter
# fill grid
x = np.linspace(1,10,10)
y = np.linspace(1,10,10)
X, Y = np.meshgrid(x,y)
Z = np.abs(np.cos(X**2 - Y**2) * X**2 * Y)
# plot
f, ax = subplots(1)
p = plt.pcolormesh(X, Y, Z, norm=LogNorm(), vmin=1e-2, vmax=1e2)
cb = plt.colorbar(p, ax=ax, orientation='horizontal', aspect=10)
minor_ticks = np.arange(1,10,2)
#cb.set_ticks(minor_ticks, minor=True) # error: doesn't support keyword argument 'minor'
#cb.ax.xaxis.set_ticks(minor_ticks, minor=True) # plots an extremely small colorbar, with wrong ticks
#cb.ax.xaxis.set_minor_locator(FixedLocator(minor_ticks)) # nothing happens
plt.show()
【问题讨论】:
标签: python matplotlib