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

"ValueError: All values in the dash list must be positive" if linewidth is set to zero in matplotlib 2.x.x #8821

Closed
Awen0121 opened this issue Jun 29, 2017 · 4 comments
Milestone

Comments

@Awen0121
Copy link

Bug report

In matplotlib 2.x.x, ValueError: All values in the dash list must be positive will be raised if linewidth is set to zero while it seems to work in matplotlib 1.5.x. No idea whether it is a bug or you intend to do so, but my macro don't work anymore because of this...

Code for reproduction

import matplotlib.pyplot as plt
x = [0, 1]
plt.plot(x, x, ls = '--', lw = 0)
plt.show()

Actual outcome

  • matplotlib 2.0.2
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__
    return self.func(*args)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 280, in resize
    self.show()
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 351, in draw
    FigureCanvasAgg.draw(self)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/lines.py", line 822, in draw
    drawFunc(renderer, gc, tpath, affine.frozen())
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/lines.py", line 1267, in _draw_lines
    self._lineFunc(renderer, gc, path, trans)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/lines.py", line 1297, in _draw_dashed
    gc.set_dashes(self._dashOffset, self._dashSeq)
  File "/home/chenyh/.local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1009, in set_dashes
    raise ValueError("All values in the dash list must be positive")
ValueError: All values in the dash list must be positive

Expected outcome

  • matplotlib1.5.1
    figure_1

Matplotlib version

  • Operating System: Tested on both Ubuntu 14.04.5 LTS / Mac OS X 10.12.5
  • Matplotlib Version: 2.0.2
  • Python Version: 2.7.13
@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jun 29, 2017
@tacaswell
Copy link
Member

This is due to scaling the dash pattern with linewidth. In 2.0.0 this scaling was clamped, in 2.0.1 or 2.0.2 (I don't remember) we removed the clamp and now lw=0 will scale the dash patterns also to 0 and hence this error.

Why are you doing this? There may be more direct ways.

@Awen0121
Copy link
Author

Awen0121 commented Jun 29, 2017

I try to narrow down the width of lines more and more and finally make them fad away.
There are for sure a lot of different treatments. But I think in this case, it is the most convenient one.
I was also very confused by the error in the beginning. Probably just to put some description about this into the error message would be good enough.

@anntzer
Copy link
Contributor

anntzer commented Jun 29, 2017

Probably the test could be replaced to error on <0 instead of <=0. (At least that works on the mpl_cairo backend).

@hanschen
Copy link

For what it's worth, I ran into this issue when trying to remove the lat/lon lines in Basemap without removing the lat/lon ticks on the axes. One solution is to set linewidth=0 (https://stackoverflow.com/a/18364872).

Glad to see that this issues has been fixed (thanks @dstansby!).

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

4 participants