1

I have been searching a lot on google to find an answer about how to plot a filled contour (contourf) of a 3D variable (lon, lat,alt), e.g. concentration, on a basemap. What I have done so far is simply to plot the 3D map with this code:

m = Basemap(width=2000000,height=2700000,
        resolution='l',projection='stere',
        lat_ts=60,lat_0=72,lon_0=-40.)

fig = plt.figure(figsize=(20,10))
ax = Axes3D(fig)

ax.azim = 290           # y rotation
ax.elev = 50            # x rotation
ax.dist = 10            # zoom

ax.add_collection3d(m.drawcoastlines(linewidth=0.25))
ax.add_collection3d(m.drawcountries(linewidth=0.35))

I have already converted longitudes and latitudes into map coordinates:

lon, lat = np.meshgrid(lons, lats)
xi, yi = m(lon, lat)

and so xi.shape and yi.shape give:

Out[288]: (500, 1260)
Out[289]: (500, 1260)

while the dimensions of the 3D variable that I want to plot are:

In [291]: BC[:,100,:,:].shape
Out[291]: (2, 500, 1260)

where 0-axis is altitude, 1-axis is latitude (xi) and 2-axis is longitude (yi).

Does anybody have an idea how to continue?

When I used ax.contourf3D() to stick with the 3D axis that I inserted in my figure (see code above), I got a message that my 3D variable should be a 2D array

When I used m.contourf3D(), I got an AttributeError: 'Basemap' object has no attribute 'contourf3D' Here's the 3D image that I created so far

3
  • I thought I understood your problem but I don't. Contour/surface plots plot 2d functions, where the height of the resulting function is the value of the alt(lat,lon) function. If I understand correctly, you have a concentration that is a function of 3 variables: conc(alt,lat,lon). This is problematic: you're trying to visualize a volume. Even if we ignore this, you'd need an at-least-length-2 array that gives you the altitudes. You probably don't need contourf3d; it's more likely that you should plot two flat contourf plots in different heights. Oct 17, 2017 at 23:12
  • Thanks for taking the time to look into this. Well, plotting 2 surface plots for each height is not what I want; this is easy using contourf(). I have done a 3D representation of an iso-surface concentration in the past using a software see here, but I was wondering if it is possible to do the same in Python. Oct 18, 2017 at 6:38
  • 3d plotting with matplotlib is actually a bit of a hack: the renderer is strictly 2d. If you want to plot something this fancy, I suggest using mayavi.mlab instead. It relies on the visualization toolkit (vtk) to create amazing, proper 3d visualizations. The tricky part would probably be putting your basemap into your mayavi plot, but you can probably extract path coordinates from Basemap in order to do that (in the worst case). Mlab is more difficult to use than matplotlib, but well worth the effort for 3d data visualization. Oct 18, 2017 at 12:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.