2010/8/10 Eric Firing <efir...@hawaii.edu>:
> On 08/10/2010 10:27 AM, Friedrich Romstedt wrote:
>> So I think it is probably best to code it into the Colormap object
>> itself, so that each and ever derived class can define its own method
>> of how to create a greyscale version.  What do you think about that?
>
> Good idea.  The base class could define a default to_grayscale() method
> that would do the conversion near the very end of the Colormap.__call__
> method if an as_gray attribute, also defined in the base class, is True.
>  No need for getters and setters--let it be a simple attribute.  This
> is much simpler than generating a whole new colormap--instead, just set
> an attribute to switch an existing colormap to gray or back to color.  I
> would leave the switch out of the __init__ args and kwargs.

> If someone
> wants grey, they can add one more line of code to set the attribute.

Hmm, one would have to do it for every colormap used.  Also, it would
be not so obvious if using the default colormap.

> I
> suspect only a small fraction of users will need this.

I like this, it's a good idea enabling to not repeat all the stuff in
the code.  But hey, wouldn't it be the same to just overload the
__call__ method?

class GrayColorbar(RgbColorbar):
    """A colorbar returning grayscaled version."""

    def __call__(self, value):
        """Transforms RgbColorbar's value into grayscale, and returns it.""""

        rgb = BaseClass.__call__(self, value)
        [do stuff]
        return grayscale

Agreed, one has to this for all the classes, while your solution works
generically in ColormapBase or whatever it's called.

Another option would be, to wrap the Colormap into a thin layer with
__call__, but this appears way too clumsy and too hacky to me.  It's a
clumsy way of deriving from the class.  Otherwise it's maybe also
nice, because it's generic, for all Colormaps.  __getattr__ and
__setattr__ (iirc) could be used to simulate the wrapped instance
fully.

Is there some layer dealing with colors in the renderers, where the
conversion could also happen?  I'm asking because of displaying color
images etc. and printing them as grayscale.  With this, we would get
rid of the alpha stuff completely, too.

Maybe a general matplotlib.rc switch 'greyscale' would be possible.
It would leave room for tons of improvement, e.g. automatically
setting the color cycle to - -- -. etc., there was some monthes ago
discussion about how to achieve that.  Another advantage: It's zero
loc if set in the config file ;-)

I think that would be a real neat new feature.

I agree what's not needed is mixed greyscale and colour display in the
same Figure.

Bear with me if my ideas are always too radical.

Friedrich

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to