I am mildly concerned about how my plots will look if
> someone prints my thesis out in grayscale. Is there an easy
> way to use the same code with one switch at the beginning to
> plot in color or grayscale? Is there a way to redefine what
> happens when I call plot(x,y,'g-') so that 'g-' no longer
> means green but now means something like color=0.75 so some
> grayscale specification?
That is an interesting problem I hadn't considered before. We have *a
lot* of colors defined in matplotlib.colors. cnames is a dict from
color names to rgb tuples (see below for example usage).
It would be useful to support custom colors in the rc file or
elsewhere -- then you could do something like
colors.mygreen : 008000
and later redefine it to gray if you need to
colors.mygreen : 808080
But you can't do that today... What you can do is manipulate the
cnames dict. I suggest creating a module like mycolors that extends
the cnames dict, and then using these custom color names in your
script. When you want to go grayscale, you just modify the colors in
from matplotlib.colors import cnames
if 1: # using color
cnames['mygreen'] = '#008000'
else: # using grayscale
cnames['mygreen'] = '#808080'
Then later, you can use it as follows:
from pylab import figure, show, nx
fig = figure()
ax = fig.add_subplot(111)
so you'll only have a single point of maintenance. We'll also accept
a patch to the rc system to support custom colors, which is the
preferred way to go.