【问题标题】:Basemap on the face of a matplotlib.mplot3d cubematplotlib.mplot3d 立方体表面的底图
【发布时间】:2011-09-03 19:18:57
【问题描述】:

正如标题所示,我正在尝试在 matplotlib.mplot3d 线图的 z=0 表面上绘制 Basemap 地图。我知道 Axes3D 对象能够在 z=0 表面上绘图(通过 Axes3D.plot、Axes3D.scatter 等),但我不知道如何使用 Basemap 对象进行绘图。希望下面的代码足够清楚地显示我需要什么。任何想法将不胜感激!

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')

【问题讨论】:

    标签: python plot matplotlib matplotlib-basemap


    【解决方案1】:

    只需将您的地图作为 3d 集合添加到 Axes3D 实例:

    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()
    

    【讨论】:

      【解决方案2】:

      AX.add_collection3d(M.drawcoastlines())

      有效但

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

      不起作用。

      添加颜色填充后,您会立即收到类似于以下内容的错误:“AttributeError: 'Polygon' object has no attribute 'do_3d_projection'”

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

      返回一个多边形数组,而不是 add_collection() 所需的输入之一。 collect.PatchCollection() 似乎也不起作用。

      那么你用什么来将 `M.fillcontinents(lake_color='#888888', color='#282828') 添加到 3D 绘图中?

      【讨论】:

        猜你喜欢
        • 2011-12-14
        • 1970-01-01
        • 1970-01-01
        • 2016-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多