Bug in Custom Dash List

I have old scripts I had made that I was rerunning in newer versions of matplotlib. They now fail because the function requires dashes to be greater than 0. I have them set to zero as below and it still throws the error. I had to set the zero in the middle to 1e-12 to get around this but is this the desired behavior? I don’t see why 0 can’t be an acceptable input to the dash function. This is on matplotlib 1.3.0rc2.

Example code:

dashes = [(1.5,1.5,3,1.5),(1,0),(1,1.2)]

legendLabels.append(ax.plot(x,y[i], color=plotColor[i%8], dashes=dashes[i%3])[0])

End of error:

/home/bigtyme/.virtualenvs/ipl/local/lib/python2.7/site-packages/matplotlib-1.3.0rc2-py2.7-linux-x86_64.egg/matplotlib/lines.pyc in _draw_lines(self, renderer, gc, path, trans)

936

937 def _draw_lines(self, renderer, gc, path, trans):

–> 938 self._lineFunc(renderer, gc, path, trans)

939

940 def _draw_steps_pre(self, renderer, gc, path, trans):

/home/bigtyme/.virtualenvs/ipl/local/lib/python2.7/site-packages/matplotlib-1.3.0rc2-py2.7-linux-x86_64.egg/matplotlib/lines.pyc in _draw_dashed(self, renderer, gc, path, trans)

981 gc.set_linestyle(‘dashed’)

982 if self._dashSeq is not None:

–> 983 gc.set_dashes(0, self._dashSeq)

984

985 renderer.draw_path(gc, path, trans)

/home/bigtyme/.virtualenvs/ipl/local/lib/python2.7/site-packages/matplotlib-1.3.0rc2-py2.7-linux-x86_64.egg/matplotlib/backend_bases.pyc in set_dashes(self, dash_offset, dash_list)

902 dl = np.asarray(dash_list)

903 if np.any(dl <= 0.0):

–> 904 raise ValueError(“All values in the dash list must be positive”)

905 self._dashes = dash_offset, dash_list

906

ValueError: All values in the dash list must be positive

Cheers,

Jeff

@mdboom, from git blame, this looks to be specifically introduced by you via [7e7b5320](https://github.com/matplotlib/matplotlib/commit/7e7b532057c08541489203697987a924e56a7aeb) on May 15th, and you even added some tests for handling path clipping. Perhaps the choice of "<=" should have been just "<"?

The problem is that a 0-length dash or space is undefined. In Agg, it causes an infinite loop (presumably because the line cursor never moves). Saving it to a PDF file and opening it in Acrobat Reader reveals a blank page (presumably because it's doing something smarter, but also basically throwing up its hands). In SVG, you get a solid line, which may or may not be the right behavior.

Given that a value of 0 doesn't make much sense anyway, I thought it best to just disallow it. Jeffrey: Do you have a good need for this?

Here's the original PR:

Mike

···

On 08/05/2013 01:36 PM, Benjamin Root wrote:

@mdboom, from git blame, this looks to be specifically introduced by you via |7e7b5320 <https://github.com/matplotlib/matplotlib/commit/7e7b532057c08541489203697987a924e56a7aeb&gt; on May 15th, and you even added some tests for handling path clipping. Perhaps the choice of "<=" should have been just "<"?|

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I think the function should be np.all(dash_list <= 0.0) instead of np.any? This works 100% fine on my machine so I think it just hangs if all values are less than or equal to zero. That hangs on my machine as you stated.

From digging into that I also realized I could have put (None, None) to get a solid line in my dash list which is what I desired but I think (1,0) is more intuitive and doesn’t cause any errors. Since dash lists have to be even number of values, could not just put (1) to get a solid line.

I guess do whichever you think is better.

Cheers,

Jeff

···

On Tue, Aug 6, 2013 at 4:14 AM, Michael Droettboom <mdroe@…86…> wrote:

  The problem is that a 0-length dash or

space is undefined. In Agg, it causes an infinite loop
(presumably because the line cursor never moves). Saving it to a
PDF file and opening it in Acrobat Reader reveals a blank page
(presumably because it’s doing something smarter, but also
basically throwing up its hands). In SVG, you get a solid line,
which may or may not be the right behavior.

  Given that a value of 0 doesn't make much sense anyway, I thought

it best to just disallow it. Jeffrey: Do you have a good need for
this?

  Here's the original PR:




  [https://github.com/matplotlib/matplotlib/pull/1999](https://github.com/matplotlib/matplotlib/pull/1999)



  Mike




  On 08/05/2013 01:36 PM, Benjamin Root wrote:
    @mdboom, from git blame, this looks to be

specifically introduced by you via [7e7b5320](https://github.com/matplotlib/matplotlib/commit/7e7b532057c08541489203697987a924e56a7aeb) on May 15th, and you even added some tests for handling path clipping. Perhaps the choice of "<=" should have been just "<"?

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent caught up. So what steps can you take to put your SQL databases under version control? Why should you start doing it? Read more to find out.
[http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk](http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk)
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
[https://lists.sourceforge.net/lists/listinfo/matplotlib-users](https://lists.sourceforge.net/lists/listinfo/matplotlib-users)

Get your SQL database under version control now!

Version control is standard for application code, but databases havent

caught up. So what steps can you take to put your SQL databases under

version control? Why should you start doing it? Read more to find out.

http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users