odd ticking in ImageGrid

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

odd ticking in ImageGrid

Slavin, Jonathan
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
[hidden email]       60 Garden Street, MS 83
phone: (617) 496-7981       Cambridge, MA 02138-1516
cell: (781) 363-0035             USA
________________________________________________________


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: odd ticking in ImageGrid

Slavin, Jonathan
Oops.  Forgot to attach the image.  Here it is.

On Wed, Jan 25, 2017 at 2:06 PM, Slavin, Jonathan <[hidden email]> 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
[hidden email]       60 Garden Street, MS 83
phone: <a href="tel:(617)%20496-7981" value="+16174967981" target="_blank">(617) 496-7981       Cambridge, MA 02138-1516
cell: <a href="tel:(781)%20363-0035" value="+17813630035" target="_blank">(781) 363-0035             USA
________________________________________________________




--
________________________________________________________
Jonathan D. Slavin                 Harvard-Smithsonian CfA
[hidden email]       60 Garden Street, MS 83
phone: (617) 496-7981       Cambridge, MA 02138-1516
cell: (781) 363-0035             USA
________________________________________________________


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

prob_demo_mpl2.0.png (22K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: odd ticking in ImageGrid

tcaswell
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 <[hidden email]> wrote:
Oops.  Forgot to attach the image.  Here it is.

On Wed, Jan 25, 2017 at 2:06 PM, Slavin, Jonathan <[hidden email]> 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
[hidden email]       60 Garden Street, MS 83
phone: <a href="tel:(617)%20496-7981" value="+16174967981" class="gmail_msg" target="_blank">(617) 496-7981       Cambridge, MA 02138-1516
cell: <a href="tel:(781)%20363-0035" value="+17813630035" class="gmail_msg" target="_blank">(781) 363-0035             USA
________________________________________________________




--
________________________________________________________
Jonathan D. Slavin                 Harvard-Smithsonian CfA
[hidden email]       60 Garden Street, MS 83
phone: <a href="tel:(617)%20496-7981" value="+16174967981" class="gmail_msg" target="_blank">(617) 496-7981       Cambridge, MA 02138-1516
cell: <a href="tel:(781)%20363-0035" value="+17813630035" class="gmail_msg" target="_blank">(781) 363-0035             USA
________________________________________________________

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users