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

Type Error in bar3d plot when saved as svg #2355

Closed
p3trus opened this issue Aug 29, 2013 · 3 comments
Closed

Type Error in bar3d plot when saved as svg #2355

p3trus opened this issue Aug 29, 2013 · 3 comments

Comments

@p3trus
Copy link

p3trus commented Aug 29, 2013

I'm getting a strange error TypeError: %x format: a number is required, not numpy.float64

The code doing this is below, a ipynb file with the full traceback is here

import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D

fig = pl.figure()
ax = Axes3D(fig)

x = y = z  = range(10)
dz =  [0., 1]*5
# I guess the problem is the dz value. Using a scalar,
# even 0. works. A list of 0. works as well but not a combination.
ax.bar3d(x, y, z, 1, 1, dz)
fig.savefig('test.svg')

matplotlib version: 1.2.0

@WeatherGod
Copy link
Member

Confirmed even in a fairly recent master.

For the record, here is my traceback.

Traceback (most recent call last):
  File "bar3d_svgbug.py", line 12, in <module>
    fig.savefig('test.svg')
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1421, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backend_bases.py", line 2220, in print_figure
    **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backend_bases.py", line 1978, in print_svg
    return svg.print_svg(*args, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backends/backend_svg.py", line 1157, in print_svg
    return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backends/backend_svg.py", line 1185, in _print_svg
    self.figure.draw(renderer)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1034, in draw
    func(*args)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/mpl_toolkits/mplot3d/axes3d.py", line 270, in draw
    Axes.draw(self, renderer)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 2086, in draw
    a.draw(renderer)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/mpl_toolkits/mplot3d/art3d.py", line 507, in draw
    return Collection.draw(self, renderer)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/collections.py", line 278, in draw
    self._offset_position)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backends/backend_svg.py", line 629, in draw_path_collection
    u'style': self._get_style(gc0, rgbFace)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backends/backend_svg.py", line 433, in _get_style
    return generate_css(self._get_style_dict(gc, rgbFace))
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/backends/backend_svg.py", line 405, in _get_style_dict
    attrib[u'fill'] = rgb2hex(rgbFace)
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.3.0rc5-py2.7-linux-x86_64.egg/matplotlib/colors.py", line 221, in rgb2hex
    return '#%02x%02x%02x' % tuple([np.round(val * 255) for val in rgb[:3]])
TypeError: %x format: a number is required, not numpy.float64

This seems to be an issue in rgb2hex(), but I don't know why this would blow up for just SVGs.

@mdboom
Copy link
Member

mdboom commented Aug 30, 2013

I think it's an issue only for SVGs because that's the only backend that calls rgb2hex.

PDF blows up like this:

/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/mpl_toolkits/mplot3d/axes3d.py:1673: RuntimeWarning: invalid value encountered in divide
  for n in normals])
Traceback (most recent call last):
  File "svg_color_crash.py", line 12, in <module>
    fig.savefig('test.pdf')
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1421, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backend_bases.py", line 2220, in print_figure
    **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backend_bases.py", line 1952, in print_pdf
    return pdf.print_pdf(*args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_pdf.py", line 2341, in print_pdf
    self.figure.draw(renderer)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1034, in draw
    func(*args)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/mpl_toolkits/mplot3d/axes3d.py", line 270, in draw
    Axes.draw(self, renderer)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/axes.py", line 2086, in draw
    a.draw(renderer)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/mpl_toolkits/mplot3d/art3d.py", line 507, in draw
    return Collection.draw(self, renderer)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/artist.py", line 54, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/collections.py", line 278, in draw
    self._offset_position)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_pdf.py", line 1586, in draw_path_collection
    self.check_gc(gc0, rgbFace)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_pdf.py", line 1459, in check_gc
    if delta: self.file.output(*delta)
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_pdf.py", line 548, in output
    self.write(fill(map(pdfRepr, data)))
  File "/home/mdboom/python/lib/python2.7/site-packages/matplotlib-1.3.0-py2.7-linux-x86_64.egg/matplotlib/backends/backend_pdf.py", line 144, in pdfRepr
    raise ValueError("Can only output finite numbers in PDF")
ValueError: Can only output finite numbers in PDF

The issue is that the color map contains NaNs. What color should that be rendered as? Fully transparent?

@efiring: Any thoughts, since you know a lot about color maps?

@tacaswell
Copy link
Member

Closing as I can no longer reproduce this.

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

No branches or pull requests

4 participants