0

I am trying to create filled contour lines on a basemap using contourf. This is the code I am using. No error occurs and it runs fine, and even the colorbar appears, but no contours are shown and the map background is only white. How do I make the contours work?

x = [1,2,3]
y = [4,5,6]
z = [7,8,9]

x = np.array(x)
y = np.array(y)
z = np.array(z)

x = np.reshape(x, (1,-1))
y = np.reshape(y, (1,-1))    
z = np.reshape(z, (1,-1))

cs = plt.contourf(x, y, z, 50, cmap='jet')
plt.colorbar()


map = Basemap(projection='cyl', resolution = 'l', area_thresh=1000.0,
          llcrnrlon = -1, llcrnrlat = -1, urcrnrlon = 7, urcrnrlat = 7)
map.drawcoastlines()
map.drawcountries()
map.drawmapboundary()
map.drawmeridians(np.arange(0, 360, 30))
map.drawparallels(np.arange(-90, 90, 30))


for lon, lat in zip(x, y):
    x, y = map(x, y)
    map.plot(x, y, 'ro', markersize = 10)

plt.show()

1 Answers1

2

You will probably have to add latlon=True to the function contourf, so it will be:

plt.contourf(x, y, z, 50, cmap='jet',latlon=True)

This makes the function to interpret your x, y data as coordinates instead of normal points.

Air
  • 8,274
  • 2
  • 53
  • 88
Numlet
  • 819
  • 1
  • 9
  • 21