Skip to content

PS backend fails to save polar plot #2828

Closed

Description

@rubenvb

This code:

from matplotlib.pyplot import figure

fig = figure()
fig.add_subplot(212, polar=True)

fig.savefig('fail.eps')

fails with this error:

Traceback (most recent call last):
  File "C:\Users\Ruben\Desktop\test.py", line 13, in <module>
    fig.savefig('fail.eps')
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\figure.py", line 1422, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 167, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backend_bases.py", line 2220, in print_figure
    **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backend_bases.py", line 1947, in print_eps
    return ps.print_eps(*args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 981, in print_eps
    return self._print_ps(outfile, 'eps', *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 1009, in _print_ps
    **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 1102, in _print_figure
    self.figure.draw(renderer)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\figure.py", line 1035, in draw
    func(*args)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\axes.py", line 2088, in draw
    a.draw(renderer)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\axis.py", line 1101, in draw
    tick.draw(renderer)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\axis.py", line 235, in draw
    self.gridline.draw(renderer)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\artist.py", line 56, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\lines.py", line 563, in draw
    drawFunc(renderer, gc, tpath, affine.frozen())
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\lines.py", line 939, in _draw_lines
    self._lineFunc(renderer, gc, path, trans)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\lines.py", line 994, in _draw_dotted
    renderer.draw_path(gc, path, trans)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 575, in draw_path
    self._draw_ps(ps, gc, rgbFace)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 907, in _draw_ps
    id = self._get_clip_path(clippath, clippath_trans)
  File "C:\WinPython-64bit-3.3.3.2\python-3.3.3.amd64\lib\site-packages\matplotlib\backends\backend_ps.py", line 556, in _get_clip_path
    id = self._clip_paths.get((clippath, clippath_transform))
TypeError: unhashable type: 'Affine2D'

This cannot be intentional.

Activity

  1. tacaswell commented on Feb 21, 2014

    @tacaswell
    Member

    What version of mpl are you using?

  2. rubenvb commented on Feb 21, 2014

    @rubenvb
    Author

    I'm using Version 1.3.1 as distributed by WinPython and/or http://www.lfd.uci.edu/~gohlke/pythonlibs/.

  3. fruitfrisje commented on Mar 19, 2014

    @fruitfrisje

    Are there already solutions to this problem, I'm having the same problem. It is in the matplotlib that it can't save polar plots....

  4. added this to the v1.4.0 milestone on Mar 19, 2014
  5. tacaswell commented on Mar 19, 2014

    @tacaswell
    Member

    @pelson Smells like something is going wrong in the transform stack.

  6. tacaswell commented on Mar 19, 2014

    @tacaswell
    Member

    @fruitfrisje @rubenvb I can not reproduce this on something close to current master. Can either of you test this using the master branch?

  7. fruitfrisje commented on Mar 19, 2014

    @fruitfrisje

    Try this:

    phi = linspace(0, 2_pi, 200)
    figure()
    polar(phi, sin(phi)_cos(phi))
    grid(True)
    savefig("plot_polar.eps", format = 'eps', dpi=1000)

    It will give the error.

    (using python 3.3.3 with Spyder 2.3.0beta3)

  8. tacaswell commented on Mar 19, 2014

    @tacaswell
    Member

    @fruitfrisje What version of mpl are you using? (matplotlib.__version__)

  9. added a commit that references this issue on Mar 19, 2014
    c1ab6c6
  10. tacaswell commented on Mar 19, 2014

    @tacaswell
    Member

    I can confirm this on master on 3.3, not on 2.7.

    This is a side effect of the change in 3 that if a class defines __eq__ then the default __hash__ goes away.

  11. fruitfrisje commented on Mar 20, 2014

    @fruitfrisje

    Sorry for the late reply (out of office), MPL version 1.3.1. We are now gong to test is in python 2.7.3. Will let you know. Is there already a workaround to solve this class problem?

  12. pelson commented on Mar 20, 2014

    @pelson
    Member

    I've not tried it, but as a workaround, before you construct the polar plot, try:

    import matplotlib.transforms as mtrans
    mtrans.Affine2D.__hash__ = id
    

    This will define a hash function on the affine transform based on the object ID (as it is in Python2) and should fix the problem. @tacaswell also has a fix in the pipeline for v1.4.

    HTH

  13. fruitfrisje commented on Mar 20, 2014

    @fruitfrisje

    The following error shows up:

    TypeError: id() takes exactly one argument (0 given)

  14. pelson commented on Mar 20, 2014

    @pelson
    Member

    Clearly there is always something to learn with Python as I don't fully undersand what the problem is, but replacing that line with:

    mtrans.Affine2D.__hash__ = lambda self: id(self)
    

    Should be fine. Anyone care to give me a lesson in Python?

  15. fruitfrisje commented on Mar 20, 2014

    @fruitfrisje

    @pelson the suggested code above works perfect! Thank you very much so far!!

    A totally other question. Is it also possible to save an excel range to an eps? (the range consists of values and text)

  16. added 2 commits that reference this issue on Mar 25, 2014
    9ff80e7
    31e2d9e
  17. added 3 commits that reference this issue on Jun 7, 2014
    a72f93d
    1a27467
    9b9c0c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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