From: tgabriel <tra...@gm...> - 2010-08-11 16:13:46
|
Problem 1: I have a dataset which has more values on one side of the scale than the other in a contour map. Matplotlib will see that I have more values towards one side of the scale, and put all of the colors in that color map to that side of the scale. For example, lets say I would like my colorbar to show values from -10^6 all the way to 10^6. But, most of my values are in the -10^6 to -10^5 range. How do I get my colorbar not to automatically send all of the colors to that portion of the colorbar and leave everything greater than -10^5 to have one color. I would like to have the colorbar displaying the same color scaling regardless of the data input. Here is a copy of my code: v2 = [-1000000,-100000,-10000,-1000,-100,-10,0,10,100,1000,10000,100000,1000000] plt.subplot(6,1,2) cset4 = plt.contourf(x2,z2,k2,v2,cmap=cm.get_cmap('jet', len(v2)-1)) cset5 = plt.contour(x2,z2,k2,v2,colors = 'k',linewidths = .22,hold='on') #set axes values plt.axis([xmin2,xmax2, zmin,zmax]) #set y axes label plt.ylabel('Z, [km]') #display title plt.title('v3 Plot Max:'+str("%.2f" %k2.max())+' Min: '+str("%.2f" %k2.min()),size='small') #colorbar manipulation cbar = plt.colorbar(cset4,spacing="uniform", shrink = 0.95,ticks=[-1000000,-100000,-10000,-1000,-100,-10,0,10,100,1000,10000,100000,1000000]) cbar.ax.set_yticklabels(['-10^5','-10^4','-10^3','-10^2','-10^1',0,'10^1','10^2','10^3','10^4','10^5']) #close file f2.close() Problem 2: If I have a colorbar scale which goes from -10 to 5, and I use one of the standard colormaps which has white in the center of it. How do I keep the zero point at the white color instead of the colorbar automatically picking the midpoint for zero? Problem 1 is much more of a pressing issue right now than problem 2. Thank you -- View this message in context: http://old.nabble.com/Disable-Colorbar-Scaling-In-Contour-Plot-tp29409978p29409978.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Friedrich R. <fri...@gm...> - 2010-08-11 18:54:48
|
2010/8/11 tgabriel <tra...@gm...>: > I would like to have the colorbar displaying the same color scaling > regardless of the data input. This /should/ be feasible with .contourf(.., vmin=VMIN, vmax=VMAX), but from the doc this isn't clear at least. If it doesn't work, we have to work out how to use the norm=... argument properly to hand over a Norm instance. Please give vmin/max a try, we can look that up if it fails. > Problem 2: If I have a colorbar scale which goes from -10 to 5, and I use > one of the standard colormaps which has white in the center of it. How do I > keep the zero point at the white color instead of the colorbar automatically > picking the midpoint for zero? So you want to set the color-MAP's range with the solution to problem 1, and display in the color-BAR only a subset of the value range used by the Norm? This has been solved already in a former task, if it suits you I can send the sources for that. Friedrich |
From: Eric F. <ef...@ha...> - 2010-08-11 19:12:43
|
On 08/11/2010 06:13 AM, tgabriel wrote: > > > Problem 1: I have a dataset which has more values on one side of the scale > than the other in a contour map. Matplotlib will see that I have more values > towards one side of the scale, and put all of the colors in that color map > to that side of the scale. > > For example, lets say I would like my colorbar to show values from -10^6 all > the way to 10^6. > But, most of my values are in the -10^6 to -10^5 range. How do I get my > colorbar not to automatically send all of the colors to that portion of the > colorbar and leave everything greater than -10^5 to have one color. > > I would like to have the colorbar displaying the same color scaling > regardless of the data input. > > Here is a copy of my code: > v2 = > [-1000000,-100000,-10000,-1000,-100,-10,0,10,100,1000,10000,100000,1000000] > plt.subplot(6,1,2) > cset4 = plt.contourf(x2,z2,k2,v2,cmap=cm.get_cmap('jet', len(v2)-1)) > cset5 = plt.contour(x2,z2,k2,v2,colors = 'k',linewidths = .22,hold='on') > #set axes values > plt.axis([xmin2,xmax2, zmin,zmax]) > #set y axes label > plt.ylabel('Z, [km]') > #display title > plt.title('v3 Plot Max:'+str("%.2f" %k2.max())+' Min: > '+str("%.2f" %k2.min()),size='small') > #colorbar manipulation > cbar = plt.colorbar(cset4,spacing="uniform", shrink = > 0.95,ticks=[-1000000,-100000,-10000,-1000,-100,-10,0,10,100,1000,10000,100000,1000000]) > > cbar.ax.set_yticklabels(['-10^5','-10^4','-10^3','-10^2','-10^1',0,'10^1','10^2','10^3','10^4','10^5']) > #close file > f2.close() I don't understand the problem based on your description and code. Please make a stand-alone example script, runnable by anyone, generating fake data as needed in the script. It should require only a little reworking of the fragment that you included above. Please include the script as an attachment, so it does not get mangled by the mail sending or reading software. Also, please specify what mpl version you are using. Eric > > Problem 2: If I have a colorbar scale which goes from -10 to 5, and I use > one of the standard colormaps which has white in the center of it. How do I > keep the zero point at the white color instead of the colorbar automatically > picking the midpoint for zero? > > Problem 1 is much more of a pressing issue right now than problem 2. > > Thank you > |
From: Eric F. <ef...@ha...> - 2010-08-11 19:24:05
|
On 08/11/2010 08:54 AM, Friedrich Romstedt wrote: > 2010/8/11 tgabriel<tra...@gm...>: >> I would like to have the colorbar displaying the same color scaling >> regardless of the data input. > > This /should/ be feasible with .contourf(.., vmin=VMIN, vmax=VMAX), > but from the doc this isn't clear at least. If it doesn't work, we > have to work out how to use the norm=... argument properly to hand > over a Norm instance. Please give vmin/max a try, we can look that up > if it fails. No, contour* do not use vmin, vmax kwargs. Setting the levels should be enough for what I thought the OP wanted to do, so I don't understand the problem--hence I requested a standalone script to illustrate it. vmin, vmax can still be set by using the plt.clim function. Maybe the OP's problem is that the colors become indistinguishable in the relatively small intervals? If so, the answer is to use a different norm, or to use a ListedColormap with a color for each interval. The ListedColormap allows complete freedom to explicitly specify the color for each interval between contour boundaries. > >> Problem 2: If I have a colorbar scale which goes from -10 to 5, and I use >> one of the standard colormaps which has white in the center of it. How do I >> keep the zero point at the white color instead of the colorbar automatically >> picking the midpoint for zero? > > So you want to set the color-MAP's range with the solution to problem > 1, and display in the color-BAR only a subset of the value range used > by the Norm? This has been solved already in a former task, if it > suits you I can send the sources for that. This sounds like a job for a custom norm, but maybe you found a better way? 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-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Eric F. <ef...@ha...> - 2010-08-11 19:30:34
|
> > Maybe the OP's problem is that the colors become indistinguishable in > the relatively small intervals? If so, the answer is to use a different > norm, or to use a ListedColormap with a color for each interval. The > ListedColormap allows complete freedom to explicitly specify the color > for each interval between contour boundaries. See http://matplotlib.sourceforge.net/examples/pylab_examples/contourf_demo.html |