Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
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 in1bfc755
def_make_key(self,*args,**kwargs): | |
'make a hashable key out of args and kwargs' | |
deffixitems(items): | |
#items may have arrays and lists in them, so convert them | |
# to tuples for the key | |
ret= [] | |
fork,vinitems: | |
# some objects can define __getitem__ without being | |
# iterable and in those cases the conversion to tuples | |
# will fail. So instead of using the iterable(v) function | |
# we simply try and convert to a tuple, and proceed if not. | |
try: | |
v=tuple(v) | |
exceptException: | |
pass | |
ret.append((k,v)) | |
returntuple(ret) | |
deffixlist(args): | |
ret= [] | |
forainargs: | |
ifiterable(a): | |
a=tuple(a) | |
ret.append(a) | |
returntuple(ret) | |
key=fixlist(args),fixitems(six.iteritems(kwargs)) | |
returnkey |
Code for reproduction
- Minimum working code:
%pylabinlineimportmatplotlibasmplfrommatplotlibimportpyplotaspltimportmpl_toolkits.axisartist.floating_axesasfloating_axestr_rotate=mpl.transforms.Affine2D().rotate(3.1459)tr=mpl.projections.polar.PolarTransform()+tr_rotategrid_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