On 08/10/2010 10:27 AM, Friedrich Romstedt wrote: > Ah, the list config got me ... (resending to list) > > 2010/8/10 Benjamin Root<ben.r...@ou.edu>: >> I am working on a function that can take a Colormap object and return a >> grayscale form of it. Ideally, I would like to return the same type of >> Colormap that was provided, but I am wondering if this is necessary. I >> supposed it is sufficient to just create a LinearSegmentedColormap from the >> self._lut data? >> >> The problem I see with that approach is that there is still possibly some >> information loss, particularly with the alpha part of the rgba data. >> LinearSegmentedColormap has a .from_list() function, but it uses only the >> rgb part of the rgba array and does not take alpha data. >> >> Is the inability of setting alpha a problem? Or maybe I should use >> deepcopy() instead? > > If you mean me, I really don't know, but I think it is always better > to do things > properly than to publish something done with the attitute "just > working" .... > > 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. I suspect only a small fraction of users will need this. If people really are going to want to fiddle with the conversion function, then the scheme above could easily be extended by allowing the as_gray attribute to be a callable; if it is a callable, then to_grayscale() would use it instead of the default function. Eric > > 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