Note that there are some explanatory texts on larger screens.

plurals
  1. POweird range value in the colorbar, matplotlib
    primarykey
    data
    text
    <p>I am a new user to the python &amp; matplotlib, this might be a simple question but I searched the internet for hours and couldn't find a solution for this. </p> <p>I am plotting precipitation data from which is in the NetCDF format. What I find weird is that, the data doesn't have any negative values in it.(I checked that many times,just to make sure). But the value in the colorbar starts with a negative value (like -0.0000312 etc). It doesnt make sense because I dont do any manipulations to the data, other that just selecting a part of the data from the big file and plotting it. </p> <p>So my code doesn't much to it. Here is the code:</p> <pre><code>from mpl_toolkits.basemap import Basemap import numpy as np import matplotlib.pyplot as plt from netCDF4 import Dataset cd progs f=Dataset('V21_GPCP.1979-2009.nc') lats=f.variables['lat'][:] lons=f.variables['lon'][:] prec=f.variables['PREC'][:] la=lats[31:52] lo=lons[18:83] pre=prec[0,31:52,18:83] m = Basemap(width=06.e6,height=05.e6,projection='gnom',lat_0=15.,lon_0=80.) x, y = m(*np.meshgrid(lo,la)) m.drawcoastlines() m.drawmapboundary(fill_color='lightblue') m.drawparallels(np.arange(-90.,120.,5.),labels=[1,0,0,0]) m.drawmeridians(np.arange(0.,420.,5.),labels=[0,0,0,1]) cs=m.contourf(x,y,pre,50,cmap=plt.cm.jet) plt.colorbar() </code></pre> <p>The output that I got for that code was a beautiful plot, with the colorbar starting from the value -0.00001893, and the rest are positive values, and I believe are correct. Its just the minimum value thats bugging me.</p> <p>I would like to know:</p> <ol> <li>Is there anything wrong in my code? cos I know that the data is right.</li> <li>Is there a way to manually change the value to 0?</li> <li>Is it right for the values in the colorbar to change everytime we run the code, cos for the same data, the next time I run the code, the values go like this " -0.00001893, 2.00000000, 4.00000000, 6.00000000 etc"</li> <li>I want to customize them to "0.0, 2.0, 4.0, 6.0 etc"</li> </ol> <p>Thanks, Vaishu</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload