# Improved dashing for black and white plots?

Hi all, this is somewhat of a half-feature request,

> half-question. I just went through a rather unpleasant
> exercise in trying to get a line plot with about 8
> traces generated for black and white printing. As it
> turns out, mpl seems to only have 4 line styles ('-',
> '--', '-.', ':'), which isn't really a whole lot
> (compare this to gnuplot's extensive dashing support).

Are you aware of the "dashes" property, which allows you to set the
exact dash pattern you want. It's an arbitrary length sequence of
alternating ink-on, ink-off, in points

# 5 points on, 2 off, 10 on, 5 off)
plot(arange(20), '--', dashes=[5,2,10,5])

> Additionally, I'd like to suggest having a b/w mode,
> where mpl's auto-selection of different colors for
> successive line plots becomes a rotation of dashing
> modes. Gnuplot's EPS backend has exactly this feature,

This seems like a good idea -- if you define a nice sequence of dashes
you want to cycle through, I'll build the rest of the infrastructure
and make a figure property like iscolor.

JDH

On this topic, here is something I used the other day (just some different dash sequences):

e, = plot(x, y, 'k', label=r'$\theta_3=%1.2f$'%(th3))
setp(e, dashes={0:(1,0), 1:(2,2), 2:(10,4), 3:(10,4,4,4), 4:(10,2,2,2), 5:(15,2,6,2)}[i])

Maybe we should just blatantly copy the gnuplot sequence, although the sequence might be gpl'ed!
One question which arises is that it wasn't clear what to set dashes to to get a solid line. I ended up doing the 0: case above i.e. (1,0), but I suspect this isn't ideal because it might generate lots of unwanted line segments. I think I tried None and (1) and it didn't work. Perhaps (999,0) would be better?

Gary R.

Thanks for these. In playing with this, both for my needs and to try
and contribute something for a permanent solution, I found something
really strange. Try running the following code in pylab:

"""Simple dashing test."""

import numpy as N
import pylab as P

dashes= { 0:(1,0),
1:(2,2),
2:(10,4),
3:(10,4,4,4),
4:(10,2,2,2),
5:(15,2,6,2) }

y = N.ones(10)+N.rand(10)

P.figure()

dashnums = dashes.keys()
dashnums.sort()
for d in dashnums:
P.plot(y,dashes=dashes[d])
# Bug??? Using this, nothing gets displayed:
y += 1
# But with this, it works fine:
#y = y+1

P.show()
# EOF

Uncomment the 'y=y+1' option, and all works fine. Here's where the
problem may be coming from, just try this in a terminal:

y = 1.0*arange(10)
plot(y)
y += rand(10)
show()

There are actually two issues here, one is definitely a bug, the other
one could be construed as a feature (albeit a surprising one):

- bug: that the script above doesn't display anything with current
SVN. I don't know why.

- feature?: that mpl holds on to the actual numpy memory buffer, so if
an array is modified in-place, any subsequent window update will
modify the plot. I can actually see this being quite useful for
monitoring a region of memory, though it can cause surprising behavior
if you are just trying to get successive plots. I guess I'm squarely
+1/-1 on how much I like it

I'll work a bit more on the dashing and send something later...

Cheers, and thanks for the hints!

f

···

On 7/11/06, Gary Ruben <gruben@...636...> wrote:

On this topic, here is something I used the other day (just some
different dash sequences):

e, = plot(x, y, 'k', label=r'$\theta_3=%1.2f$'%(th3))
setp(e, dashes={0:(1,0), 1:(2,2), 2:(10,4), 3:(10,4,4,4), 4:(10,2,2,2),
5:(15,2,6,2)}[i])

> Hi all, this is somewhat of a half-feature request,
> half-question. I just went through a rather unpleasant
> exercise in trying to get a line plot with about 8
> traces generated for black and white printing. As it
> turns out, mpl seems to only have 4 line styles ('-',
> '--', '-.', ':'), which isn't really a whole lot
> (compare this to gnuplot's extensive dashing support).

Are you aware of the "dashes" property, which allows you to set the
exact dash pattern you want. It's an arbitrary length sequence of
alternating ink-on, ink-off, in points

In my humble defense, the fact that this is barely mentioned in the
pylab tutorial, not at all in the plot docstring, and also not in
Perry's tutorial, may have something to do with my not knowing about
it

# 5 points on, 2 off, 10 on, 5 off)
plot(arange(20), '--', dashes=[5,2,10,5])

> Additionally, I'd like to suggest having a b/w mode,
> where mpl's auto-selection of different colors for
> successive line plots becomes a rotation of dashing
> modes. Gnuplot's EPS backend has exactly this feature,

This seems like a good idea -- if you define a nice sequence of dashes
you want to cycle through, I'll build the rest of the infrastructure
and make a figure property like iscolor.

Here's a specific, backwards-compatible proposal: why not add a new
format string type, '-N', with N running 0-9, and '-0' being identical
to a '-' (i.e., a continuous line). I think that having easy access
to continuous plus 9 dashing patterns should be enough for most
purposes (a plot with more than 10 traces on it is just unreadable
anyway). This mode also makes it code-friendly, so that one can
easily select any of the patterns with code of the type

'-%s' % n

where n is being looped over, or a key from a dict, whatever.

I'm not quite sure what the best 9 patterns should be, so I'm
attaching a script to make it easy to test a bunch of them in a
hurry. This can help us find 9 distinctive ones (the gnuplot ones are
good, but I think we can do better), to put them into this basic list.
The little script can also be added to the examples dir to showcase
the 9 basic patterns once selected (and you can make a figure for the
tutorial with it

Cheers,

f

dashes.py (733 Bytes)

···

On 7/10/06, John Hunter <jdhunter@...4...> wrote: