Hi,

On 11.06.06, John Owens wrote:
> discretepalette takes one argument, a dictionary, with the following
> structure:
> - Index to the dictionary is the number of colors (n_indicies);
> - Result of indexing into the dictionary is another dictionary, this
>   time indexed by color index (1-n);
> - Result of indexing into this sub-dictionary is a third dictionary,
>   with 'r', 'g', and 'b' entries, each a float from 0.0-1.0.
> 
> Then the "select" call just uses index and n_indices to look up the
> right color. Here's the discretepalette code:
> 
> class discretepalette(palette):
> 
>     """discretepalette needs description"""
> 
>     def __init__(self, colors):
>         palette.__init__(self)
>         self.mycolors = colors
> 
>     def select(self, index, n_indices):
>         """return a color corresponding to an index out of n_indices"""
>         return rgb(self.mycolors[n_indices][index+1]['r'],
>                    self.mycolors[n_indices][index+1]['g'],
>                    self.mycolors[n_indices][index+1]['b'])
> 
> And here's a palette that I also put in color.py that works:
> 
> palette.Pastel2        = discretepalette(
>                     {3: {1: {'r': 0.70196078431372544, 'b': 
> 0.80392156862745101, 'g': 0.88627450980392153},
>                          3: {'r': 0.79607843137254897, 'b': 
> 0.90980392156862744, 'g': 0.83529411764705885}, 
>                          2: {'r': 0.99215686274509807, 'b': 
> 0.67450980392156867, 'g': 0.80392156862745101}}, 
>                      4: {1: {'r': 0.70196078431372544, 'b': 
> 0.80392156862745101, 'g': 0.88627450980392153}, 
>                          3: {'r': 0.79607843137254897, 'b': 
> 0.90980392156862744, 'g': 0.83529411764705885}, 
>                          2: {'r': 0.99215686274509807, 'b': 
> 0.67450980392156867, 'g': 0.80392156862745101}, 
>                          4: {'r': 0.95686274509803926, 'b': 
> 0.89411764705882357, 'g': 0.792156862745098}}, 
>                      ...
> 
> Then using the palette is just like any other palette:
> 
> rotatingstyle = graph.style.symbol(
>   graph.style.symbol.changesquare,
>   symbolattrs=[deco.filled, color.palette.Pastel1])
> 
> rotatinglinestyle = graph.style.line(
>   [style.linewidth.THIck, 
>    style.linestyle.solid,
>    color.palette.Accent])

I would suggest to use a changeable attribute iterating over a list of
colors:

Pastel2 = attr.changelist([color.rgb(0.70196078431372544, 0.88627450980392153, 
0.80392156862745101),
                           color.rgb(0.79607843137254897, 0.83529411764705885, 
0.90980392156862744),
                           color.rgb(0.99215686274509807, 0.80392156862745101, 
0.67450980392156867),
                           color.rgb(0.95686274509803926, 0.792156862745098,   
0.89411764705882357)])

That's what changelist is created for.

> I'd be happy to add all the colorbrewer palettes if there was
> interest, but it would need the discretepalette support for that.
> 
> Feedback? It's simple code which is nice. :)

First of all I think some good color schemes are very useful. They
could be used by many PyX users and its a good idea to include some
handy defaults in the PyX core. However, I don't like the wording. At
the moment palettes are *not* just changeable attributes and are *not*
discrete (by definition). Maybe we're using the wrong wording and your
discrete palettes is what palettes really should be (since people
expect that). We need a second word here and I want to make that being
related to discrete color spaces as we can (and will) add support for
discrete color spaces on PostScript and PDF level later on. Sure we
could start to use continuouspalette and discretepalette, but maybe
we could come up with some better wording (even containing "index"
somehow). For example, a palette could get a indexed method which
takes an argument (how many discrete colors should be taken from the
palette) and it then returns an "indexedcolorspace". The
"indexedcolorspace" could be a changeable attribute at the same time
but with a fixed number of colors (instead of a variable number for
palettes).


André

-- 
by  _ _      _    Dr. André Wobst
   / \ \    / )   [EMAIL PROTECTED], http://www.wobsta.de/
  / _ \ \/\/ /    PyX - High quality PostScript and PDF figures
 (_/ \_)_/\_/     with Python & TeX: visit http://pyx.sourceforge.net/


_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to