From: Oz N. <na...@gm...> - 2008-07-16 19:58:48
|
Here is why the contours are wrong: they are ploted verticaly, while I think, it is more common to draw temp. contours in oceanography when the are horizontal. Also, one more thing, I can't find how to expand the borders of the plot, say from 350 to 400 (same for depth) I tried usig xlim and ylim(0,900) but no result. Here is my code now, I can't really get it, ha ? another issue is that I've added anoter temp. series but it won't show it. I still see 3 rows. from matplotlib import pyplot as plt from pylab import * temperature=[ [9,8,6], [9,7,6], [9,7,6], [9,6,6] ] distance = (0,200,350) depth = (100,250,250,700) x = distance y = depth z = temperature #m = plt.contourf(x,y,z) m = plt.contour(x,y,z) ylabel('Depth') xlabel('Distance') ylim(0,1200) #plt.xlim(0,500) plt.gca().invert_yaxis() #plt.colorbar(m) import numpy as np X, Y = np.meshgrid(x,y) #plt.hold(True) # probably not necessary plt.plot(X,Y, 'o') plt.show(m) On Wed, Jul 16, 2008 at 10:28 PM, Eric Firing <ef...@ha...> wrote: > Oz Nahum wrote: > >> Hi Eric, >> really thanks for your help so far. I am doing a quick short course, and >> I'll do the examples later. >> I've fixed the code, here it is: >> >> from matplotlib import pyplot as plt >> temperature=[ >> [10,8,6], >> [9,7,5], >> [8,7,4] >> ] >> >> distance = (100,200,300) >> depth = (100,300,700) >> >> x = distance >> y = depth >> z = temperature >> >> m = plt.contourf(x,y,z) >> plt.gca().invert_yaxis() >> plt.colorbar(m) >> plt.show(m) >> >> the trouble now that the contours seems wrong... and my question still >> stands. I'd like to do the plot as said: contours + series, can you show me >> where I'm wrong ? >> > > The plot looks right to me--I see 4 degrees in the lower RH corner, 300 > distance units and 700 depth units. Why do you say the contours seem > wrong? > > As for plotting the "series", what do you mean? Put circles on the data > points? Then include something like this, after the call to contourf: > > import numpy as np > X, Y = np.meshgrid(x,y) > plt.hold(True) # probably not necessary > plt.plot(X,Y, 'o') > > > > Eric > >> >> thanks, Oz >> >> >> On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing <ef...@ha... <mailto: >> ef...@ha...>> wrote: >> >> Oz Nahum wrote: >> >> Ok, I played with it a little bit. >> >> Here is what I know: >> importing the data is not a big issue, I aready wrote a tutorial >> about it here: >> http://www.tabula0rasa.org/?p=21 >> >> here is a sample code I wrote. >> from matplotlib import pyplot as plt >> from pylab import * >> temperature=[ >> [1,3,4], >> [2,4,5], >> [6,3,2] >> ] >> >> distance = (100,200,300) >> depth = (10,30,50) >> >> plt.colorbar() >> plt.contourf(distance,depth,temperature) >> plt.gca().invert_yaxis() >> plt.show() >> >> >> >> Can I plot the dots as different series on top of the contours ? >> >> >> First you have to make your basic example work; what you posted >> above does not. >> 1) For an example like this, use a different number of points in the >> x and y directions, to make it clear how the arrays are oriented. >> 2) The colorbar command must *follow* the contourf command. >> 3) Make your test temperature profiles more reasonable, i.e. >> temperature decreasing with depth, so you can see whether your plot >> is doing the right thing. >> 4) Omit the "from pylab import *" >> 5) Once you start doing real work, you will need numpy. The >> suggested import syntax is "import numpy as np". >> 6) Study the examples that come with mpl. >> >> Eric >> >> >> > |