I am using matplotlib to create 2d line-plots. For the purposes of publication, I would like to have those plots in black and white (not grayscale), and I am struggling to find a non-intrusive solution for that.
Gnuplot automatically alters dashing patterns for different lines, is something similar possible with matplotlib?
Below I provide functions to convert a colored line to a black line with unique style. My quick test showed that after 7 lines, the colors repeated. If this is not the case (and I made a mistake), then a minor adjustment is needed for the “constant”
COLORMAPin the provided routine.Here’s the routine and example:
This provides the following two plots:


First in color:
Then in black and white:
You can adjust how each color is converted to a style. If you just want to only play with the dash style (-. vs. — vs. whatever pattern you want), set the
COLORMAPcorresponding ‘marker’ value toNoneand adjusted the ‘dash’ pattern, or vice versa.For example, the last color in the dictionary is ‘k’ (for black); originally I had only a dashed pattern
[1,2,1,10], corresponding to one pixel shown, two not, one shown, 10 not, which is a dot-dot-space pattern. Then I commented that out, setting the dash to (None,None), a very formal way of saying solid line, and added the marker ‘o’, for circle.I also set a ‘constant’ MARKERSIZE, which will set the size of each marker, because I found the default size to be a little large.
This obviously does not handle the case when your lines already have a dash or marker patter, but you can use these routines as a starting point to build a more sophisticated converter. For example if you original plot had a red solid line and a red dotted line, they both would turn into black dash-dot lines with these routines. Something to keep in mind when you use them.