|
From: John H. <jdh...@ac...> - 2006-04-17 15:13:42
|
>>>>> "Ryan" == Ryan Krauss <rya...@gm...> writes:
Ryan> I am mildly concerned about how my plots will look if
Ryan> someone prints my thesis out in grayscale. Is there an easy
Ryan> way to use the same code with one switch at the beginning to
Ryan> plot in color or grayscale? Is there a way to redefine what
Ryan> happens when I call plot(x,y,'g-') so that 'g-' no longer
Ryan> means green but now means something like color=0.75 so some
Ryan> 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
mycolors.
# mycolors.py
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:
import mycolors
from pylab import figure, show, nx
fig = figure()
ax = fig.add_subplot(111)
ax.plot((1,2,3), color='mygreen')
show()
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.
JDH
|