|
From: Ryan K. <rya...@gm...> - 2006-04-17 15:42:48
|
Is there a similar dictionary for linetypes? I would anticipate needing to use more linetypes in grayscale than in color (i.e. everything could be solid in color). Thanks again, Ryan On 4/17/06, Ryan Krauss <rya...@gm...> wrote: > I am making some progress. The following script works, but you have > to shut down ipython if you want to switch from color to grayscale: > > from numpy import arange, sin, cos, pi > import matplotlib.colors > reload(matplotlib.colors) > cnames=3Dmatplotlib.colors.cnames > from pylab import figure, show, nx, clf, cla > fig =3D figure(4) > ax =3D fig.add_subplot(111) > t=3Darange(0,1,0.01) > y=3Dsin(2*pi*t) > grayscale=3D0 > if not grayscale: # using color > cnames['mygreen'] =3D '#008000' > else: # using grayscale > cnames['mygreen'] =3D '#808080' > > #ax.plot(t,y, color=3Dcnames['green']) > ax.plot(t,y, color=3D'mygreen') > show() > > Is there some command to refresh the system color dictionary? > > Thanks, > > Ryan > > On 4/17/06, John Hunter <jdh...@ac...> wrote: > > >>>>> "Ryan" =3D=3D 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=3D0.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'] =3D '#008000' > > else: # using grayscale > > cnames['mygreen'] =3D '#808080' > > > > > > Then later, you can use it as follows: > > > > import mycolors > > from pylab import figure, show, nx > > fig =3D figure() > > ax =3D fig.add_subplot(111) > > ax.plot((1,2,3), color=3D'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 > > > |