如何使用 python 在地理地图上将边绘制为 3D 弧线?

How to draw edges as 3D arcs on a geographic map using python?

我想创建一个类似于

的网络地图

在 python 中。到目前为止,我能够在 2D 上绘制它。边缘的密度使图形不整洁。在 3-D 中绘制边缘将增强美感并使其更具吸引力。 任何帮助将不胜感激。提前致谢

原则上,Basemap可以做到你想做的事。您可以在 this tutorial and then just plot your arcs on top of that. However, if you want to colour different countries the way your example figure implies, you have to start dealing with shapefiles (see for instance or 之后的 3D 轴中绘制 Basemap。无论如何,下面是一个在 3D 图中绘制底图和弧线的示例代码。在 3D 轴上绘制底图的部分直接取自我上面链接的教程。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.basemap import Basemap
from matplotlib.collections import PolyCollection
import numpy as np

m = Basemap()

fig = plt.figure()
ax = Axes3D(fig)

ax.azim = 270
ax.elev = 50
ax.dist = 8

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

polys = []
for polygon in m.landpolygons:
    polys.append(polygon.get_coords())


lc = PolyCollection(polys, edgecolor='black',facecolor='#DDDDDD', closed=False)
ax.add_collection3d(lc)

def plot_arc(ax,p1,p2,height,N=100):
    x = np.linspace(p1[0],p2[0],N)
    y = np.linspace(p1[1],p2[1],N)
    z = (1-np.linspace(-1,1,N)**2)*height
    ax.plot(x,y,z)

plot_arc(ax,(-70,0),(80,50),1)
plot_arc(ax,(80,50),(125,-25),1)
plot_arc(ax,(125,-25),(-70,0),1)

plt.show()

这里是示例代码的结果:

希望对您有所帮助。