Pablo Romero wrote:
> 
> Im experiencing unexpected behavior with contourf.
> Im trying to plot float values of '0.0', while also using the following 
> levels array with contourf():
> 
> Lv=(0,1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
> 
> I've attached a sample image of the output.
> the areas in white are contours where the plot values are exactly '0.0'.

The land areas, right?

In a simple test, I don't see what you are describing:

In [1]:Lv=(0,1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)

In [2]:norm = mpl.colors.BoundaryNorm(Lv,256)

In [4]:norm([0.0])
Out[4]:
masked_array(data = [0],
              mask = [False],
        fill_value = 999999)


In [5]:z = linspace(0.0, 19.0, 20).reshape(4,5)

In [6]:z
Out[6]:
array([[  0.,   1.,   2.,   3.,   4.],
        [  5.,   6.,   7.,   8.,   9.],
        [ 10.,  11.,  12.,  13.,  14.],
        [ 15.,  16.,  17.,  18.,  19.]])

In [7]:contourf(z, norm=norm)
Out[7]:<matplotlib.contour.ContourSet instance at 0x9eaadac>

In [8]:contourf(z, Lv, norm=norm)
Out[8]:<matplotlib.contour.ContourSet instance at 0xa1ca98c>


0.0 is getting mapped to 0 by the norm, and that is used as an index to 
select the first cmap color, the darkest blue.

Is your Z an ndarray or is it a masked array? What you describe is 
consistent with the 0 values actually being masked, so they are not 
being contoured at all--except that contourf has a bug with internal 
masked regions so that they don't always get left unfilled.

In the example above, compare with

In [15]:figure()
Out[15]:<matplotlib.figure.Figure object at 0xa3879cc>

In [16]:contourf(ma.masked_less_equal(z, 0.0), Lv, norm=norm)
Out[16]:<matplotlib.contour.ContourSet instance at 0xa38790c>

Now, the problem with this hypothesis is that printing the masked array 
does *not* show the 0.0 value:

In [14]:print ma.masked_less_equal(z, 0.0)
[[-- 1.0 2.0 3.0 4.0]
  [5.0 6.0 7.0 8.0 9.0]
  [10.0 11.0 12.0 13.0 14.0]
  [15.0 16.0 17.0 18.0 19.0]]


so I don't understand what is going on in your case.


What is the result from typing

type(Z)
norm([Z[-1,0]])

in ipython (after generating Z, of course)?


> 
> I am not using the "extend='min|both'" in my contourf() function call.
> If I use the "extend='min|both'" option, it will plot the '0.0' plot values 
> using the color of the 1st-2nd level (blue). However, for my application, I 
> DO NOT want to use the 'extend' option; I want my contour & colorbar levels 
> to start at 0.
> 

We should figure out what the problem really is.  If the 0.0 (land) 
values are being treated as below the 0 boundary, then you should be 
able to control their color like this:

cmap = cm.jet
cmap.set_under(cmap(0)) # to make it the same as the 0-1 color
contourf(X, Y, Z, Lv, norm=norm, cmap=cmap)



> So, in theory,the '0.0' float values *should* be considered to be at the 
> '0->1' range within my levels array, correct?
> 

Yes, and as noted above, when I test it, it is.

Eric

> Im not sure how to create an example that can reproduce my data with '0.0' 
> float values.
> this is more/less the basis of the code I used to create the attached plot 
> image:
> 
> # assume Z is my dataset



> 
> Z=create_my_data()
> 
> # setup basemap instance
> # I call contourf from the basemap instance
> # but the problem still exists even when
> # contourf is called from pyplot instance
> 
> m=basemap(...)
> ...
> 
> print "Z: ",Z
> 
> # this prints the following
> # this is the best I can do to demonstrate what my data in 'Z' looks like
> #
> # Z: [[11.9459991455 11.9789991379 12.0119991302 ..., 8.51399993896
> # 8.05200004578 7.55699968338]
> # [12.375 12.4079999924 12.4409999847 ..., 9.00899982452 8.57999992371
> # 8.08500003815]
> # [12.8039999008 12.8369998932 12.8699998856 ..., 9.43799972534
> # 9.07499980927 8.64599990845]
> # ...,
> # [0.0 0.0 0.0 ..., 4.52099990845 5.2469997406 5.90700006485]
> # [0.0 0.0 0.0 ..., 6.13800001144 6.33599996567 6.73199987411]
> # [0.0 0.0 0.0 ..., 4.98299980164 5.64299964905 6.26999998093]]
> 
> # my plotting code
> 
> Lv=(0,1,3,5,6,7,8,9,10,12,14,16,18,20,25,30,35,40,50,75)
> norm = mpl.colors.BoundaryNorm(Lv,256)
> cs = m.contourf(X,Y,Z,Lv,norm=norm,cmap=cm.jet)
> plt.colorbar(cs)
> plt.show()
> 
> 
> I believe that matplotlib is having issues with comparing the "zero"- value 
> level & '0.0' array values in my plot; it seems like its considering the 
> '0.0' values to be 'less than zero' and thus not plotting them within the 
> 'zero-through-one' level of my levels array. It seems as though its plotting 
> these '0.0' values using the color assigned to the cmap's "set_under" 
> property (anything below the 1st layer gets plotted in white or the 
> 'set_under' color). is this correct?
> 
> Ive tried setting the first value in my levels array to '0.0' instead of just 
> '0', but the results were the same.
> 
> Is this a bug; the fact that the '0.0' are not being associated with the '0' 
> level?
> 
> Please help,
> P.Romero

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to