Closed
Description
Bug report
Bug summary
Axes with transforms (PolarTransform or CompositeGenericTransform) cannot be added to a subplot in python3. This appears to be due to the fact that matplotlib fails to create a hashable version of these objects for the purpose of making a dictionary key in
matplotlib/lib/matplotlib/figure.py
Lines 823 to 851 in 1bfc755
Code for reproduction
- Minimum working code:
%pylab inline
import matplotlib as mpl
from matplotlib import pyplot as plt
import mpl_toolkits.axisartist.floating_axes as floating_axes
tr_rotate = mpl.transforms.Affine2D().rotate(3.1459)
tr = mpl.projections.polar.PolarTransform() +tr_rotate
grid_helper = floating_axes.GridHelperCurveLinear(tr, extremes=(0, 6.28318, 10., 20.))
fig = plt.figure()
ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
fig.add_subplot(ax1, transform=tr)
Actual outcome
- Traceback from using python3 running in a Jupyter notebook:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py in add(self, key, a)
122 try:
--> 123 hash(key)
124 except TypeError:
TypeError: unhashable type: 'CompositeGenericTransform'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-2-d333d90be1c9> in <module>()
11 ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
12
---> 13 fig.add_subplot(ax1, transform=tr)
/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs)
1021 a = subplot_class_factory(projection_class)(self, *args, **kwargs)
1022
-> 1023 self._axstack.add(key, a)
1024 self.sca(a)
1025 a._remove_method = self.__remove_ax
/usr/local/lib/python3.5/dist-packages/matplotlib/figure.py in add(self, key, a)
123 hash(key)
124 except TypeError:
--> 125 raise ValueError("first argument, %s, is not a valid key" % key)
126
127 a_existing = self.get(key)
TypeError: not all arguments converted during string formatting
Expected outcome
- Figure generated by python2 in a Jupyter notebook:
Matplotlib version
-
Matplotlib version: 2.0.0
-
Python version: 3.5.2 (bug) / 2.7.12 (working)
-
Platform: Ubuntu 16.04
-
Python was installed using apt.
-
Matplotlib was installed using pip.
Metadata
Metadata
Assignees
Labels
No labels