Hi Jeff, Yes you are right! Apologies. Whilst it is easy enough to define the grid in this case as it is a regular lat,long grid. If it was for example a geostationary grid, I think this might be more difficult. Is there a way to return the grid for example from the basemap call, which can then be used in the contour call?
I hope that makes sense. Thanks again. Jeff Whitaker wrote: > > On 7/22/10 7:48 AM, mdekauwe wrote: >> import numpy as np >> from mpl_toolkits.basemap import Basemap >> import matplotlib.pyplot as plt >> >> # generate some random data - i.e. what would be an image of the world, >> say >> different >> # land covers >> data = np.random.randint(10,27,100*67).reshape(100, 67) >> >> # I want to draw a boundary round each land cover type, so >> # classify a new array >> data2 = np.where(data == 10, 1, data) >> data2 = np.where(data == 11, 1, data) >> data2 = np.where(data == 13, 2, data) >> data2 = np.where(data == 14, 2, data) >> data2 = np.where(data == 15, 2, data) >> data2 = np.where(data == 16, 2, data) >> data2 = np.where(data == 18, 3, data) >> data2 = np.where(data == 19, 3, data) >> data2 = np.where(data == 20, 3, data) >> data2 = np.where(data == 26, 4, data) >> data2 = np.where(data == 27, 4, data) >> >> plt.contour(data2) >> plt.show() >> sys.exit() >> >> this pops up a contour plot... >> >> Now what if as I do I want to overlay this on a basemap plot... >> >> import numpy as np >> from mpl_toolkits.basemap import Basemap >> import matplotlib.pyplot as plt >> >> # generate some random data - i.e. what would be an image of the world, >> say >> different >> # land covers >> data = np.random.randint(10,27,100*67).reshape(100, 67) >> >> # I want to draw a boundary round each land cover type, so >> # classify a new array >> data2 = np.where(data == 10, 1, data) >> data2 = np.where(data == 11, 1, data) >> data2 = np.where(data == 13, 2, data) >> data2 = np.where(data == 14, 2, data) >> data2 = np.where(data == 15, 2, data) >> data2 = np.where(data == 16, 2, data) >> data2 = np.where(data == 18, 3, data) >> data2 = np.where(data == 19, 3, data) >> data2 = np.where(data == 20, 3, data) >> data2 = np.where(data == 26, 4, data) >> data2 = np.where(data == 27, 4, data) >> >> fig = plt.figure(figsize=(8, 6)) >> m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5, >> resolution='c', projection='cyl') >> ax = fig.add_axes([0.1, 0.1, 0.6, 0.7]) >> m.ax = ax >> >> delta = 0.03 >> x = np.arange(1.5, 3.5, delta) >> y = np.arange(10.5, 13.5, delta) >> X, Y = np.meshgrid(x, y) >> >> im = m.imshow(data, interpolation='nearest', cmap=plt.cm.jet) >> m.contour(data2, X, Y, color='black') >> > > Martin: This needs to be > > m.contour(X, Y, data2, colors='black') > > (the data goes after the coordinate arrays, and the keyword is 'colors', > not 'color') > > > -Jeff > > >> plt.show() >> >> This only plots the basemap without the contours? >> >> Many thanks, >> >> Martin >> >> >> > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://old.nabble.com/Basemap-%2B-contour-layer--tp29235080p29237306.html Sent from the matplotlib - users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users