I'm having some trouble setting up a pcolormesh plot with a colorbar that includes logarithmically spaced minor tick marks on the colorbar.
The closest I've come is something like this:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
xbins = np.linspace(0, 1, 50)
ybins = np.linspace(0, 1, 50)
data = np.random.random((49,49))
fig, ax = plt.subplots()
im = ax.pcolormesh(xbins, ybins, data, norm=matplotlib.colors.LogNorm())
cb = fig.colorbar(im)
cb.ax.minorticks_on()
plt.savefig('test.png')
The trouble with this solution is that the minor ticks are spaced evenly in log space:
I'd like to set up the plot so I have evenly spaced minor ticks in linear space, which should show up unevenly spaced on this plot.
I know that I can manually set the minor tick labels using a FixedFormatter
, but I'd prefer not to do that if possible since I will be making a large number of plots automatically.
MultipleLocator
for the minor ticks...subs
keyword of matplotlib.org/api/ticker_api.html#matplotlib.ticker.LogLocator ?cb.ax.set_yscale('log', xsubs=[2,3,4,5,6,7,8,9])
produces this plot: i.imgur.com/amCHR5j.pngcb.ax.yaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(base=0.1))
, but that doesn't work either: i.imgur.com/wzlTIMx.png. It looks like the colorbar y axis is really linear and goes from 0 to 1. (I guess LogNorm() does that?)