Base map on cube surface matplotlib.mplot3d

As the name implies, I'm trying to build a Basemap map on the surface z = 0 of the line of the matplotlib.mplot3d line. I know that an Axes3D object can build on a surface z = 0 (via Axes3D.plot, Axes3D.scatter, etc.), but I can’t figure out how to do this with a Basemap object. Hope the code below shows what I need quite clearly. Any ideas would be greatly appreciated!

import matplotlib.pyplot as pp
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap

# make sample data for 3D lineplot
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)

# make the 3D line plot
FIG = ct.pp.figure()
AX = Axes3D(FIG)
AX.plot(x, y, z, '-b')

# make the 2D basemap
### NEEDS TO SOMEHOW BE AT z=0 IN FIG
M = ct.Basemap(projection='stere', width=3700e3, height=2440e3,
               lon_0=-5.0, lat_0=71.0, lat_ts=71.0,
               area_thresh=100, resolution='c')
PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')
+3
source share
2 answers

Just add the map to the 3d collection in your Axes3D instance:

import numpy as np
import matplotlib.pyplot as pp
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap

theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-500, 500, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)

FIG = pp.figure()
AX = Axes3D(FIG)
AX.plot(x, y, z, '-b')

M = Basemap(projection='stere', width=3700e3, height=2440e3,
               lon_0=-5.0, lat_0=71.0, lat_ts=71.0,
               area_thresh=100, resolution='c')
AX.add_collection3d(M.drawcoastlines())
AX.grid(True)

pp.draw()
pp.show()
+1
source

AX.add_collection3d(M.drawcoastlines())

works but

PATCHES = M.fillcontinents(lake_color='#888888', color='#282828')

does not work.

, , : "AttributeError: " Polygon " do_3d_projection"

M.fillcontinents(lake_color='#888888', color='#282828')`

, , add_collection(). collect.PatchCollection() .

, `M.fillcontinents(lake_color = '# 888888', color = '# 282828') 3D-?

-2

All Articles