简体   繁体   English

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

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

I want to create a network map similar to 我想创建一个类似于

在此处输入图片说明

in python. 在python中。 So far I am able to draw it on 2D. 到目前为止,我已经能够在2D上绘制它。 The density of edges is making the graph untidy. 边缘的密度使图形变得不整齐。 Plotting the edges in 3-D would enhance the beauty and make it more appealing. 在3-D中绘制边缘会增强美感,并使其更具吸引力。 Any help would be highly appreciated. 任何帮助将不胜感激。 Thanks in advance 提前致谢

In principle, what you want to do is possible with Basemap . 原则上,您可以使用Basemap You can draw a Basemap in a 3D axis following this tutorial and then just plot your arcs on top of that. 您可以按照本教程在3D轴上绘制Basemap ,然后在其上绘制圆弧。 However, if you want to colour different countries the way your example figure implies, you have to start dealing with shapefiles (see for instance here or here ). 但是,如果您想按照示例图所暗示的方式为不同的国家/地区着色,则必须开始处理shapefiles (例如,请参见此处此处 )。 Anyway, below an example code that plots the Basemap and the arcs in a 3D plot. 无论如何,在示例代码下可以绘制底图和3D图中的弧。 The part that plots the Basemap in the 3D axes is taken directly from the tutorial I linked above. 在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()

Here the result of the example code: 这里是示例代码的结果:

以上代码的结果

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM