|
From: Sudheer J. <sud...@ya...> - 2013-03-02 11:35:44
|
Hi Phil, Though iris looked to be promising it needed many other libraries, so I chose the below suggestion. But is there a way to overlay contours on this ? also is it possible to specify the levels? In [23]: plt.pcolormesh?? did not give much help with best regards, Sudheer ________________________________ From: Phil Elson <pel...@gm...> To: "Mat...@li..." <mat...@li...> Sent: Saturday, 2 March 2013 3:40 PM Subject: Re: [Matplotlib-users] depth longitude plot Incidentally, if you wanted to do this a little more expressively than indexing, you could look into using iris (http://scitools.org.uk/iris/docs/latest/index.html). It doesn't currently support DAP, but if you had the NetCDF file (from http://www.marine.csiro.au/dods-data/climatology-netcdf/levitus_monthly_temp_98.nc) you would do: importiris import iris.quickplot as qplt import matplotlib.pyplot as plt temp_cube = iris.load_cube('levitus_monthly_temp_98.nc') # Sort out some of the bad metadata. Firstly, set the unit, # secondly rename the dimension 1 coordinate to 'depth'. temp_cube.unit = 'C' temp_cube.coord(dimensions=1, dim_coords=True).rename('depth') # Extract a spatial sub-domain. sub_temp_cube = temp_cube.extract(iris.Constraint(latitude=0.5, longitude=lambda v: 45 < v < 100)) # Iterate over all the depth-longitude sections (in this case it # iterates over time) for cross_sect_cube in sub_temp_cube.slices(['depth', 'longitude']): qplt.pcolormesh(cross_sect_cube) plt.gca().invert_yaxis() plt.show() break Hope that helps! Phil On 2 March 2013 09:37, Phil Elson <pel...@gm...> wrote: Perhaps something like: > > > > >from matplotlib import pyplot as plt >from netCDF4 import Dataset >import numpy as np > > > > >url='http://www.marine.csiro.au/dods/nph-dods/dods-data/climatology-netcdf/levitus_monthly_temp_98.nc' >ds = Dataset(url) > > > > >temp = ds.variables['TEMP'] >lats = ds.variables['lat'] >lons = ds.variables['lon'] >depths = ds.variables['z'] > > > > ># filter all but one latitude >lat_index = np.where(lats[:] == 0.5)[0][0] >lats = lats[lat_index] > > ># filter a range of longitudes >lon_lower_index = np.where(lons[:] == 44.5)[0][0] >lon_upper_index = np.where(lons[:] == 100.5)[0][0] >lons = lons[lon_lower_index:lon_upper_index] > > >temp = temp[0, :, lat_index, lon_lower_index:lon_upper_index] > > > > >plt.pcolormesh(lons, depths[:], temp) >plt.gca().invert_yaxis() > > >plt.show() > > > > > > > > >The indexing approach used here is quite flakey, so I certainly wouldn't use this in anything operational. > >Hope this helps, > >Phil > > ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users |