Skip to content

ImageGrid crashes when specifying axes class #3750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
astrofrog opened this issue Nov 1, 2014 · 6 comments
Closed

ImageGrid crashes when specifying axes class #3750

astrofrog opened this issue Nov 1, 2014 · 6 comments
Milestone

Comments

@astrofrog
Copy link
Contributor

The ImageGrid class claims to be able to work with any Axes sub-class, but this is not the case:

import numpy as np
from matplotlib.axes import Axes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid import ImageGrid

im = np.arange(100)
im.shape = 10, 10

fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111, # similar to subplot(111)
                nrows_ncols = (2, 2), # creates 2x2 grid of axes
                axes_pad=0.1, # pad between axes in inch.
                axes_class=(Axes, {})
                )

for i in range(4):
    grid[i].imshow(im)

plt.show()

The error is:

Traceback (most recent call last):
  File "t.py", line 13, in <module>
    axes_class=(Axes, {})
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 647, in __init__
    self.set_label_mode(label_mode)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 422, in set_label_mode
    _tick_only(ax, bottom_on=True, left_on=False)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/axes_grid1/axes_grid.py", line 36, in _tick_only
    ax.axis["bottom"].toggle(ticklabels=bottom_off, label=bottom_off)
TypeError: 'method' object is not subscriptable

In fact, it looks like it might be expecting an AxisArtist instance. Should the docstring be updated, or should this be treated as a bug?

@tacaswell
Copy link
Member

From quickly skimming the code in mpl_toolkit (which I have never really looked at before) I think the docstring needs to be updated.

There is a tremendous amount of cool looking code there that we should probably do a through survey of....

attn @leejjoon

@astrofrog
Copy link
Contributor Author

@tacaswell - I feel like ImageGrid should be generalizable to any axes class though, just had a look at the code and it seems that the bug is only happening because of the code that hides the labels (which can be done, just differently, for normal Axes)?

@tacaswell
Copy link
Member

Even better.

I was looking at the axis artist code, and realizing we have two implementations of Axes in the library, not at imagegrid.

@leejjoon
Copy link
Contributor

leejjoon commented Nov 2, 2014

axes_grid toolkit has been tightly associated with the axis artist thing. Initially it only supported axis_artist.Axes. Later I added a support for matplotlib's original Axes, but I did it by implementing a wrapper class around original Axes (see mpl_axes.py).

As @astrofrog already mentioned, we can modify the axes_grid code to support any derivatives of original Axes class. I still see some commented out code that was used to support original Axes, so this may not need a lot of effort. However, I suggest we leave the axis-artist-related code as it is since they are not fully compatible.

Alternative way is to implement a factory function for mpl_axes.Axes (as is done for Subplot), and create a new subclass when required. I prefer this but this may just reflect my preference to the axis-artist.

@tacaswell
Copy link
Member

http://matplotlib.org/mpl_toolkits/axes_grid/ seems to provide some warning about this, but I am not sure how readily findable that page is (nor does it seem that axes_grid1 really not use the custom classes).

pelson referenced this issue Feb 1, 2015
DOC : add caveat to mpl_toolkits ImageGrid
@tacaswell
Copy link
Member

Closed by #4015 and #4016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants