Hi everybody,

I have a problem with LinearSegmentedColormap.
In the example below (see PS), I make a colormap, and use it to plot an 
EllipseCollection. My plot is parameterized by a quantity that I have named 
"large_value". For large_value equal to 257, a blue point is obtained at 
(x=0.3, y=0.4). But for large_value equal to 258, it becomes black.

This is because of the way LinearSegmentedColormap is working. It has a 
parameter N which allows to set the "number of colors":

http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

It is 256 by default, so if I increase N to a greater value, the point remains 
blue for large_value equal to 258.

Now, my real plot (not this dummy example) is such that I need N to be very 
large so as to obtain the right colors on my plot, although very few colors 
are used at the end.
However, when N is too large, the plot becomes very slow, and a lot of memory 
is used; I think because an array is probably built with this size, although 
in theory there is no need to construct such a complete array.

Is there an easy workaround, or have I to study and modify the matplotlib code 
myself?

Thanks,

TP

PS: Here is the test code:
##################
from pylab import *
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.collections import CircleCollection

ioff()
large_value = 257 # blue below this value
#large_value = 258 # black above this value
N = 1e5 # 256 by default

cdict = { 'blue': [(0.0, 0.0, 0.0),
                    (2*1/large_value, 1, 1)
                    , (1.0, 1.0, 1.0)]
                    ,  'green': [(0.0, 0.0, 0.0),
                        (2*1/large_value, 0, 0)
                        , (1.0, 1.0, 1.0)]
                    , 'red': [(0.0, 0.0, 0.0),
                            (2*1/large_value, 0, 0),
                            (1.0, 1.0, 1.0)] }

measures= array([[ 0.2,   0.3,   1],
       [  0.3,   0.4,   2],
       [  0.5,   0.6,   large_value]])

cmap = LinearSegmentedColormap( "cmap foobar"
        , cdict
       # , N= N )
        )

fig = figure()
axes = fig.add_subplot(111)
ec = CircleCollection( [80]
        , offsets = measures[:,:2]
        , transOffset = axes.transData
        )

ec.set_array( measures[:,2] )
ec.set_cmap( cmap )
axes.add_collection( ec )

show()
##################

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to