[Matplotlib-users] odd ticking in ImageGrid

Thomas Caswell tcaswell at gmail.com
Wed Jan 25 14:42:35 EST 2017


That is a tick label from the x-axis of the color bar.

grid.cbar_axes[0].xaxis.set_major_locator(NullLocator())
grid.cbar_axes[0].xaxis.set_minor_locator(NullLocator())

should fix it.  This looks like it is a bug (or two) in axis_grid, can you
please create an issue?

Using

fig.colorbar(im, cax=grid.cbar_axes[0])

to create the colorbar also works (and does not require manually tweaking
the ticks on the colorbar).

Tom

On Wed, Jan 25, 2017 at 2:14 PM Slavin, Jonathan <jslavin at cfa.harvard.edu>
wrote:

> Oops.  Forgot to attach the image.  Here it is.
>
> On Wed, Jan 25, 2017 at 2:06 PM, Slavin, Jonathan <jslavin at cfa.harvard.edu
> > wrote:
>
> Hi,
>
> Since upgrading to matplotlib 2.0.0 I've found that one of the plots I
> made before has odd behavior in ticking.  Sample code to reproduce the
> problem is as follows:
>
> import matplotlib.pyplot as plt
> import numpy as np
> from matplotlib.colors import LogNorm,Normalize
> from mpl_toolkits.axes_grid1 import ImageGrid
>
> fig = plt.figure()
> grid = ImageGrid(fig, 111, nrows_ncols = (2,2), share_all =
>         True, add_all=True, label_mode = 'L', cbar_mode = 'single')
>
> for g in grid:
>     image = (10.**(3.*np.random.rand(100))).reshape((10,10))
>     im = g.imshow(image, origin='lower', norm=LogNorm(),
>             interpolation='none', extent=(0., 29.9, 0., 29.9),
>             cmap='viridis', vmin=1.,vmax=1.E3)
>
> grid.cbar_axes[0].colorbar(im)
> grid.cbar_axes[0].set_yticks([1.,10.,100.,1.E3])
> grid.cbar_axes[0].set_yticklabels([r'$1.0$', r'$10$',r'$10^{2}$',
> r'$10^{3}$'])
>
> plt.show()
>
> ​The result I get is shown in the attached image.  The issue is the "2 x
> 10^0" in the lower right. It seems that it's associated with the colorbar,
> but doing things like grid.cbar_axes[0].set_xticks([]) has no effect.  If I
> don't include the colorbar that annotation doesn't get created.  It also
> seems to be associated with using norm=LogNorm().  In fact if I don't
> include setting the yticks and yticklabels on the colorbar, I get that "2
> x10^0" label and "None" at the upper right.  So, this certainly seems like
> some sort of bug.  It doesn't to that using version 1.5.  I can submit a
> bug report if desired.
>
> Jon​
>
> --
> ________________________________________________________
> Jonathan D. Slavin                 Harvard-Smithsonian CfA
> jslavin at cfa.harvard.edu       60 Garden Street, MS 83
> phone: (617) 496-7981       Cambridge, MA 02138-1516
> cell: (781) 363-0035             USA
> ________________________________________________________
>
>
>
>
> --
> ________________________________________________________
> Jonathan D. Slavin                 Harvard-Smithsonian CfA
> jslavin at cfa.harvard.edu       60 Garden Street, MS 83
> phone: (617) 496-7981       Cambridge, MA 02138-1516
> cell: (781) 363-0035             USA
> ________________________________________________________
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170125/3ab472ff/attachment.html>


More information about the Matplotlib-users mailing list