Hello,I want to plot two sets of masked data on a single plot and I can not get exactly the kind of image I want to. I have tried pcolormesh and contourf and both have problems. With contourf the inner data does not look smooth and sometimes has a row of missing data around it, with pcolormesh, on the other hand, I can not control the levels in the way I want to. So, as is in the documentation, contourf may have problems with masked data, so I can skip that solution. But how do I achieve controlled color levels as I can do with contourf, but using pcolormesh? Attached code illustrates the images I get with two methods.
Best regards, Andres
''' Demonstrate use of a log color scale in contourf ''' from matplotlib import pyplot as P import numpy as np from numpy import ma from matplotlib import colors, ticker from matplotlib.mlab import bivariate_normal from matplotlib.ticker import LogLocator, LogFormatter N = 100 x = np.linspace(-3.0, 3.0, N) y = np.linspace(-2.0, 2.0, N) X, Y = np.meshgrid(x, y) # A low hump with a spike coming out of the top right. # Needs to have z/colour axis on a log scale so we see both hump and spike. # linear scale only shows the spike. z = (bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)) # Put in some negative values (lower left corner) to cause trouble with logs: z[:5, :5] = -1 # The following is not strictly essential, but it will eliminate # a warning. Comment it out to see the warning. z = ma.masked_where(z<= 0, z) # Automatic selection of levels works; setting the # log locator tells contourf to use a log scale: #cs = P.contourf(X, Y, z, locator=ticker.LogLocator()) # Alternatively, you can manually set the levels # and the norm: lev_exp = np.arange(np.floor(np.log10(z.min())-1), np.ceil(np.log10(z.max())+1)) #levs = np.power(10, lev_exp) levstr=[] levs=[0.00001,0.00005,0.0001,0.0005,0.001,0.01,0.1,1,10] for i in levs: levstr.append(str('%1.5f' % i)) #print levs zmask1=ma.masked_where(z.data<2,z) zmask2=ma.masked_where(z.data>=2,z) ### To include all values of levels, not just the logarithms l_f = LogFormatter(2,labelOnlyBase=False) ### USE pcolormesh fig=P.figure() P.title('w pcolormesh') cs = P.pcolormesh(zmask1, levs=levs,cmap=P.cm.Blues, norm=colors.LogNorm()) P.colorbar(format=l_f) cs = P.pcolormesh(zmask2, levs=levs,cmap=P.cm.Greens, norm=colors.LogNorm()) P.colorbar(format=l_f) ### USE contourf fig=P.figure() P.title('w contourf') cs = P.contourf(zmask2,levs,cmap=P.cm.Greens, norm=colors.LogNorm()) P.colorbar(format=l_f) cs = P.contourf(zmask1,levs, cmap=P.cm.Blues, norm=colors.LogNorm()) P.colorbar(format=l_f) #cbar.ax.set_yticklabels(levstr) P.show() #P.savefig('test')
------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users