0

My aim is to plot some data and merge it with the world map. I produce data using Delaunay triangulation, like this:

u = np.array(lat)
v = np.array(lon)
x = u
y = v
z = np.array(iwv)
tri = Delaunay(np.array([u,v]).T)
plt.tricontourf(y, x, z, lev, triangles=tri.simplices)
plt.colorbar()
plt.show()

I also make a map using mpl_toolkits:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(projection='merc',llcrnrlat= 35,urcrnrlat=60,llcrnrlon=0,urcrnrlon=30,resolution='c', suppress_ticks=True)
m.drawcountries()
m.drawcoastlines()
plt.show()

These procedures give me two consequtive separated pictures with the results of triangulation and the map. How can I merge them and get picture with both map and result of triangulation? Thank you in advance.

To armatita. Thank you for your answer, but it doesn't help. When I run this code:

u = np.array(lat)
v = np.array(lon)
x = u
y = v
z = np.array(iwv)
tri = Delaunay(np.array([u,v]).T)
lev = np.linspace(0, 0.1, 100)
m = Basemap(projection='merc',llcrnrlat= 35,urcrnrlat=60,llcrnrlon=0,urcrnrlon=30,resolution='c', suppress_ticks=True)
m.drawcountries()
m.drawcoastlines()
plt.tricontourf(y, x, z, lev, triangles=tri.simplices)
plt.colorbar()
plt.show()

I get just an empty map with color bar.

To dl.meteo: Thank you, but when I'm trying to do that, I get the next message:

> Traceback (most recent call last):   File
> "/home/anton/PycharmProjects/final/test.py", line 76, in <module>
>     plot = m.contourf(x1, y1,z, lev)   File "/usr/lib/pymodules/python2.7/mpl_toolkits/basemap/__init__.py", line
> 521, in with_transform
>     return plotfunc(self,x,y,data,*args,**kwargs)   File "/usr/lib/pymodules/python2.7/mpl_toolkits/basemap/__init__.py", line
> 3644, in contourf
>     xx = x[x.shape[0]/2,:] IndexError: too many indices

As I understand, the third argument in contourf() should be a 2D-array, but triangulation returns 1D-array.

Anton
  • 55
  • 6
  • You have two instances of plt.show(), remove the first and run the plot instructions sequentially (so one after the other). Once all instructions are done (for both plots), do plt.show() – armatita Mar 17 '16 at 14:18

1 Answers1

0

You have to reference m (map) to your variables x and y .

x,y = m(lats,lons)

and then you have to initialize the contour

plot = m.contour(x,y)

I hope this helps, i am a beginner too ;)

dl.meteo
  • 1,658
  • 15
  • 25