Skip to content
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

PS backend fails to save polar plot #2828

Closed
rubenvb opened this issue Feb 21, 2014 · 13 comments · Fixed by #2927
Closed

PS backend fails to save polar plot #2828

rubenvb opened this issue Feb 21, 2014 · 13 comments · Fixed by #2927
Milestone

Comments

@rubenvb
Copy link

rubenvb commented Feb 21, 2014

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.

@tacaswell
Copy link
Member

What version of mpl are you using?

@rubenvb
Copy link
Author

rubenvb commented Feb 21, 2014

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

@fruitfrisje
Copy link

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....

@tacaswell tacaswell added this to the v1.4.0 milestone Mar 19, 2014
@tacaswell
Copy link
Member

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

@tacaswell
Copy link
Member

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

@fruitfrisje
Copy link

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)

@tacaswell
Copy link
Member

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

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Mar 19, 2014
python3 requires that if a class defines __eq__ then in must define
__hash__ (so that if a == b then hash(a) == hash(b)).  Define 64bit
hash by pulling the first 8 characters out of a sha1 hash of the matrix

closes matplotlib#2828
@tacaswell
Copy link
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.

@fruitfrisje
Copy link

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?

@pelson
Copy link
Member

pelson commented Mar 20, 2014

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

@fruitfrisje
Copy link

The following error shows up:

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

@pelson
Copy link
Member

pelson commented Mar 20, 2014

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?

@fruitfrisje
Copy link

@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)

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Mar 25, 2014
Base key on the string version of the transform matrix

Closes matplotlib#2828
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Mar 25, 2014
Base key on the string version of the transform matrix

Closes matplotlib#2828
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 7, 2014
Base key on the id of the transform.  This maintains
the old behavior and does not break the python hashable
object model.

changed the variable id -> pid so as to not shadow the
method `id`

Closes matplotlib#2828
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 7, 2014
Base key on the id of the transform.  This maintains
the old behavior and does not break the python hashable
object model.

changed the variable id -> pid so as to not shadow the
method `id`

Closes matplotlib#2828
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jun 9, 2014
Base key on the id of the transform.  This maintains
the old behavior and does not break the python hashable
object model.

changed the variable id -> pid so as to not shadow the
method `id`

Closes matplotlib#2828
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants