You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: auto locate minor ticks on log scaled color bar #7141
Matplotlib version 1.5.1, Python version 2.7.6 (Enthought Canopy) and OSX
As detailed in this stack overflow post, you have to explicitly specify the minor tick locations on a log scaled color bar. It would be nice if matplotlib would do this for you, instead of having to call minorticks = p.norm(np.hstack([np.arange(2, 10, 1)/10.0, np.arange(2, 10, 1)/1.0]) in the code below
importnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.colorsimportLogNormx=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)
f, ax=plt.subplots()
p=plt.pcolormesh(X, Y, Z, norm=LogNorm(), vmin=1e-2, vmax=1e2)
cb=plt.colorbar(p, ax=ax, orientation='horizontal', aspect=10)
# We need to nomalize the tick locations so that they're in the range from 0-1...minorticks=p.norm(np.hstack([np.arange(2, 10, 1)/10.0, np.arange(2, 10, 1)/1.0]))
cb.ax.xaxis.set_ticks(minorticks, minor=True)
plt.show()
Thanks, @Kojoley. cb.ax.minorticks_on() gives evenly spaced minor tick marks in log space, which is not what I want. In my opinion, the default should be evenly spaced minor tick marks in linear space, which translate to unevenly spaced minor tick marks in log space.
The trouble is, I have tried using cb.ax.minorticks_on() and a LogLocator to place the minor tick marks where I want them, but I cannot get them to work together. (The problem might be that the color bar expects tick marks to be normalized from 0 to 1.) The only method that works for me is
I am glad to see that minor ticks are placed properly now, but tick length on minor tick should be shorter than major ticks, IMHO. That's how it used to be (see Kojoley's Sep 20th post). Perhaps the minor tick length is just a rcParams setting...
No, it will take more work to fix that. It won't happen for 2.0. It requires substantial change to the colorbar tick-handling, which differs from normal axis tick handling because there is an additional transformation between the colorbar tick values and the axis coordinates. The colorbar does not support major and minor ticks; it has only major ticks. It has a single ticks kwarg and a single format kwarg, together with the machinery to use their values, or suitable defaults based on the norm. Directly setting the minor ticks as in the example at the top of this issue will not work correctly in general because the data limits don't necessarily correspond to the (0, 1) colorbar axis coordinates.
This is related to the confusing intersection among scales, transforms, norms, tickers, and the necessarily unique characteristics of a colorbar. I would prefer to see it handled in the course of a larger code cleanup and refactoring rather than by merely adding a bunch of code to the already-complex colorbar. (Actually, my mind is wavering; hacking minor ticks into the colorbar is conceptually straightforward, and probably the API changes--adding 2 kwargs--would be the same as we would end up with after a major re-write.)
I will open a separate issue for this.
Activity
story645 commentedon Sep 20, 2016
Can you please provide a picture? Might be easier to evaluate what you're after that way.
Kojoley commentedon Sep 20, 2016
Default:

With minor ticks:

Kojoley commentedon Sep 20, 2016
cb.ax.minorticks_on()works in a different way:breedlun commentedon Sep 20, 2016
Thanks, @Kojoley.
cb.ax.minorticks_on()gives evenly spaced minor tick marks in log space, which is not what I want. In my opinion, the default should be evenly spaced minor tick marks in linear space, which translate to unevenly spaced minor tick marks in log space.The trouble is, I have tried using
cb.ax.minorticks_on()and aLogLocatorto place the minor tick marks where I want them, but I cannot get them to work together. (The problem might be that the color bar expects tick marks to be normalized from 0 to 1.) The only method that works for me isThus, this seems to be a little more than a simple change to the default settings.
tacaswell commentedon Sep 20, 2016
attn @efiring
QuLogic commentedon Dec 11, 2016
On current
v2.x, this:looks like this by default:

so I guess this has been fixed?
efiring commentedon Dec 11, 2016
Closed by #7438.
breedlun commentedon Dec 11, 2016
I am glad to see that minor ticks are placed properly now, but tick length on minor tick should be shorter than major ticks, IMHO. That's how it used to be (see Kojoley's Sep 20th post). Perhaps the minor tick length is just a rcParams setting...
efiring commentedon Dec 11, 2016
No, it will take more work to fix that. It won't happen for 2.0. It requires substantial change to the colorbar tick-handling, which differs from normal axis tick handling because there is an additional transformation between the colorbar tick values and the axis coordinates. The colorbar does not support major and minor ticks; it has only major ticks. It has a single
tickskwarg and a singleformatkwarg, together with the machinery to use their values, or suitable defaults based on the norm. Directly setting the minor ticks as in the example at the top of this issue will not work correctly in general because the data limits don't necessarily correspond to the (0, 1) colorbar axis coordinates.This is related to the confusing intersection among scales, transforms, norms, tickers, and the necessarily unique characteristics of a colorbar. I would prefer to see it handled in the course of a larger code cleanup and refactoring rather than by merely adding a bunch of code to the already-complex colorbar. (Actually, my mind is wavering; hacking minor ticks into the colorbar is conceptually straightforward, and probably the API changes--adding 2 kwargs--would be the same as we would end up with after a major re-write.)
I will open a separate issue for this.
breedlun commentedon Dec 11, 2016
Ok. Thank you for the detailed reply. I probably would have spent 30 minutes figuring that out on my own.
Removed work arounds for log scaled color bars that were needed for m…