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

savefig crashes in backend_p[df|s].py when using plot-option mew #3332

Closed
juisoo opened this issue Jul 31, 2014 · 8 comments
Closed

savefig crashes in backend_p[df|s].py when using plot-option mew #3332

juisoo opened this issue Jul 31, 2014 · 8 comments

Comments

@juisoo
Copy link

juisoo commented Jul 31, 2014

Debian Wheezy
Python 2.7.3
matplotlib 1.1.1rc2

I have a simple plot with a marker which I want to save to PDF/EPS with savefig. When setting the markeredgewidth I get an Error from savefig or rather backend_pdf.py. The same holds for eps export. Here's the traceback (MWE for this behaviour below):
Traceback (most recent call last):
File "mwe.py", line 13, in
fig.savefig('mmo_example_1.pdf',format='pdf')
File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1185, in savefig
self.canvas.print_figure(_args, *_kwargs)
File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 2021, in print_figure
*_kwargs)
File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1789, in print_pdf
return pdf.print_pdf(_args, **kwargs)
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_pdf.py", line 2191, in print_pdf
file.close()
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_pdf.py", line 482, in close
self.writeMarkers()
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_pdf.py", line 1212, in writeMarkers
bbox = bbox.padded(lw * 0.5)
TypeError: can't multiply sequence by non-int of type 'float'

# python

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

t = np.arange(-0.9999, 0.0, 0.001)

fig = plt.figure(figsize=(7.,5.))
ax = fig.add_axes([0.13,0.13,0.82,0.82])

ax.plot(t,0.2*np.sin(4*t)+t + np.sign(t)*0.5,'r-o',mfc='white',mec='r',mew='1',markevery=(500,1000)) # produces the following errror when using savefig:
#  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_pdf.py", line 1212, in writeMarkers
#    bbox = bbox.padded(lw * 0.5)
#TypeError: can't multiply sequence by non-int of type 'float'

#ax.plot(t,0.2*np.sin(4*t)+t + np.sign(t)*0.5,'r-o',mfc='white',mec='r',markevery=(500,1000))  # works like a charm

plt.draw()

fig.savefig('mmo_example_1.eps',format='eps')
fig.savefig('mmo_example_1.pdf',format='pdf')

plt.show()

@jenshnielsen
Copy link
Member

That is a very old version of Matplotlib. Could you please try with a newer version. Preferably the latest release candidate of 1.4.0

@juisoo
Copy link
Author

juisoo commented Jul 31, 2014

Well, yes, it is indeed. However, it's the most current there is for Debian Wheezy (packaged). As I don't have sudo or root permissions on my machine and have no idea how to install it locally and then import it, I would need a little nudge in the right direction.
Anyway I figured, it might be less hassle for someone with a current version to run the MWE and check if the problem persists.

@juisoo
Copy link
Author

juisoo commented Jul 31, 2014

Note that the Error message and traceback for eps export differ slightly from the pdf-ones posted above:

Traceback (most recent call last):
  File "mwe.py", line 21, in <module>
    fig.savefig('mmo_example_1.eps',format='eps')
  File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 1185, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 2021, in print_figure
    **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1784, in print_eps
    return ps.print_eps(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_ps.py", line 954, in print_eps
    return self._print_ps(outfile, 'eps', *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_ps.py", line 987, in _print_ps
    **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_ps.py", line 1080, in _print_figure
    self.figure.draw(renderer)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/figure.py", line 898, in draw
    func(*args)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/axes.py", line 1997, in draw
    a.draw(renderer)
  File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/matplotlib/lines.py", line 556, in draw
    rgbFace)
  File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_ps.py", line 589, in draw_markers
    ps_cmd.append('%.1f setlinewidth' % lw)
TypeError: float argument required, not str

[TAC edited to add mark up]

@jenshnielsen
Copy link
Member

I think that the issue is that mew should be the integer 1 not the string '1'
For some reason the string works in the display backend but not the pdf and eps backends.

@jenshnielsen
Copy link
Member

The doc string says

markeredgewidth or mew: float value in points

So you can replace integer with float in the above.

@juisoo
Copy link
Author

juisoo commented Jul 31, 2014

Thanks Jens! That was it.
In the meanwhile I learned how to install python modules locally. And, yes, the "problem" persists in 1.4.x.
Now this could be closed marked "Not a bug", however, IMO, this behaviour (working in display but not in pdf/ps backend) violates the principle of least surprise.
I would suggest therefore to make the display backend more strict in only accepting number values and/or throw an exception or at least a warning when when passing a string value to option mew

@jenshnielsen
Copy link
Member

Agreed there is scope for improving the validation of input parameters to plot et. al.

@tacaswell
Copy link
Member

I suspect that someplace in the agg layer there is a (maybe implicit) cast to float involved in going down to c++, whereas in this case the value is being thrown (un-validated) at a string formatter or being used in multiplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants