Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Transforms Cannot be Added to Subplots in Python3 #8395

Closed
Milestone
@w2naf

Description

@w2naf

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

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
. There is no bug in the python2 version.

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:

download

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp