Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: David Huard <david.huard@gm...>  20060202 17:03:03
Attachments:
text/plain
discrete_colors.png

From: Eric Firing <efiring@ha...>  20060202 19:27:29

David, It is possible that I made this discretization problem worse when I modified some of the color handling code. In any case, I would like to come up with one or more good, clean solutions, but I may need a few days. The problem is with the normalization (the norm kwarg), not the colormap, which is little more than a list of colors. The trick may be making sure any change in the norm code doesn't mess up the way contour and colorbar work. One workaround is to calculate Xindex from X, where Xindex is an integer array the same size as X but containing the desired index into the colormap for each value of X, and then call imshow(Xindex, cmap = bone10, norm = colors.no_norm) I think this should work, but I haven't tried it yet. Eric David Huard wrote: > Hi, > > I want to display a cumulative distribution function (i.e. a function > going from 0 to 1) using a discrete colormap. That is, I want the values > from 0 to .1 to be mapped to one color, .1 to .2 to another color and so > on, so the quantiles can be seen at a glance. To do so, I tried to > discretize the existing color maps, for example, I tried > bone10 = matplotlib.colors.LinearSegmentedColormap('bone10', > cm._bone_data, 10) > > and then plotted the matrix using > imshow(X, cmap = bone10) > > I included a figure showing on the left what I got using the standard > colormap bone and on the right what I obtain using bone10. As you can > see, the differences are important. The whole upper part of the > distribution is warped by the discrete colormapping. It seems that the > only values that are mapped to white are the values equal to 1. I > figured out this must be the quantization errors that the docstrings of > cm.bone warns about. My question is : is this the standard way to do > what I want and I'm not doing it properly, or it simply isn't the "right > way"? Curiously, the colorbar displays the right behavior. > > In short, should I define a new colormap from scratch, with anchors at > [0, .1, .2, ..., .9, 1.] and the colorspace explicitely defined, or is > there a shortcut? > > Thanks in advance for advice. > > David > >  > 
From: Eric Firing <efiring@ha...>  20060202 20:59:10

David, Two more things: 1) Have you considered using contourf instead of imshow, or would it be inappropriate? 2) Please send me the code for the X array that you used in your example. Thanks. Eric David Huard wrote: > Hi, > > I want to display a cumulative distribution function (i.e. a function > going from 0 to 1) using a discrete colormap. That is, I want the values > from 0 to .1 to be mapped to one color, .1 to .2 to another color and so > on, so the quantiles can be seen at a glance. To do so, I tried to > discretize the existing color maps, for example, I tried > bone10 = matplotlib.colors.LinearSegmentedColormap('bone10', > cm._bone_data, 10) > > and then plotted the matrix using > imshow(X, cmap = bone10) .... 
From: Eric Firing <efiring@ha...>  20070207 01:37:43

Claas Teichmann wrote: > Hi David and Eric, > > one year ago, you discussed a discretazation of the colorbar with > imshow() in matplotlibusers. The topic was "DIscretization of > colorbar". Did you succeed in using a discrete colorbar? Yes, I completely rewrote the colorbar code, and it is now quite flexible. > > I put a request to the mailinglist with the topic "Wrong > colorbarticks in imshowcolorbar with 10 colors". Maybe one of you > already got the answer? > > Many greetings! > > Claas :) Assuming you have a reasonably recent version of mpl, you can modify your colorbar call this way: colorbar(ticks=linspace(im.norm.vmin, im.norm.vmax, 11)) (This is for your example with a 10entry colormap.) Because of a default parameter that is not exposed, it will label only every second color boundary in the example from your earlier message. To make it label every boundary, you could use from matplotlib import ticker ticks = linspace(im.norm.vmin, im.norm.vmax, 11) tickmaker = ticker.FixedLocator(ticks, nbins=20) # make nbins >= number of ticks colorbar(ticks=tickmaker) Eric 
From: David Huard <david.huard@gm...>  20070207 14:16:05
Attachments:
Message as HTML

You can also take a look at the wiki http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations There you'll find the code I had about colormap discretization. Maybe it does the same thing Eric discussed, however. Cheers, David 2007/2/6, Eric Firing <efiring@...>: > > Claas Teichmann wrote: > > Hi David and Eric, > > > > one year ago, you discussed a discretazation of the colorbar with > > imshow() in matplotlibusers. The topic was "DIscretization of > > colorbar". Did you succeed in using a discrete colorbar? > > Yes, I completely rewrote the colorbar code, and it is now quite flexible. > > > > > I put a request to the mailinglist with the topic "Wrong > > colorbarticks in imshowcolorbar with 10 colors". Maybe one of you > > already got the answer? > > > > Many greetings! > > > > Claas :) > > Assuming you have a reasonably recent version of mpl, you can modify > your colorbar call this way: > > colorbar(ticks=linspace(im.norm.vmin, im.norm.vmax, 11)) > > (This is for your example with a 10entry colormap.) > > Because of a default parameter that is not exposed, it will label only > every second color boundary in the example from your earlier message. > To make it label every boundary, you could use > > from matplotlib import ticker > ticks = linspace(im.norm.vmin, im.norm.vmax, 11) > tickmaker = ticker.FixedLocator(ticks, nbins=20) > # make nbins >= number of ticks > colorbar(ticks=tickmaker) > > Eric > >  > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with preintegrated technology to make your job > easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.asus.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers > 
From: Claas Teichmann <claas.teichmann@gm...>  20070209 13:11:03

Hi Eric, Great that it works!! This is what I was looking for! There is one thing left, which is that the tick labels are not exactly at the boundary between the colors. (It is no problem for me, but I am interested where it comes from). The script below shows that the colorswitch is not exactly at an "even" number. The values 0.022000001 and 0.022 are colored with the same color, whereas 0.02200001 has a different color. I don't know whether this is the reason for the ticks not beeing exactly at the intersection..? I used the newest matplotlib version from the svnrepository. I would use a script in the following way: from pylab import * from matplotlib import ticker delta = 0.01 x = arange(3.0, 3.0, delta) y = arange(3.0, 3.0, delta) X,Y = meshgrid(x, y) Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) Z = Z2  Z1 # difference of Gaussians Z[20,20]=0.022 Z[20,25]=0.022000001 Z[20,30]=0.02200001 Z[20,35]=0.0220001 Z[20,40]=0.022001 Z[20,45]=0.02201 cmap = cm.get_cmap('jet', 10) # 10 discrete colors #### Set vmin and vmax beforehand im = imshow(Z, cmap=cmap, vmin=0.15, vmax=0.17, interpolation='nearest') colorbar(ticks=linspace(im.norm.vmin, im.norm.vmax, 11)) # 11 tick labels Thanks! Claas :) 
From: Eric Firing <efiring@ha...>  20070209 19:01:59

Claas Teichmann wrote: > Hi Eric, > > Great that it works!! This is what I was looking for! > > There is one thing left, which is that the tick labels are not exactly > at the boundary between the colors. (It is no problem for me, but I am > interested where it comes from). The script below shows that the > colorswitch is not exactly at an "even" number. The values > 0.022000001 and 0.022 are colored with the same color, whereas > 0.02200001 has a different color. I don't know whether this is the > reason for the ticks not beeing exactly at the intersection..? When I run the script below I don't see what you are describing above; but I may not be looking in the right place, and it would not surprise me if there are little anomalies like this, because we are dealing with floating point arithmetic. I do see (and had noticed before) that the colorbar ticks look a tiny bit high. I don't know whether this is a bug or whether it is a consequence of the fact that colors are assigned to ranges that include the lower limit but not the upper limit, and/or floating point arithmetic, and/or the resolution of the display. Or it may be because of some floating point fudge factors that I put into the colorbar code. Maybe these could be improved. Eric 