底图加3d图

问题描述 投票:0回答:1

Hello Stackoverflow分叉器,

我是一个热心的蟒蛇学习者。我研究过python来描绘我关于人口密度的个人项目。

我已经在python中学习了关于matplotlib和底图的教程。我想到了将我的三维图形映射到底图上的想法,这允许我使用地理坐标信息。

任何人都可以让我知道如何使用底图作为三维图的基准平面?

请让我知道我可以用哪些教程或参考资料来开发它。

最好的,谢谢你总是Stackoverflow分叉。

matplotlib-basemap
1个回答
0
投票

basemap documentation有一小部分关于3D绘图。这是一个简单的脚本,可以帮助您入门:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

plt.close('all')
fig = plt.figure()
ax = fig.gca(projection='3d')
extent = [-127, -65, 25, 51]

# make the map and axis.
m = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[2],
             urcrnrlon=extent[1], urcrnrlat=extent[3],
             projection='cyl', resolution='l', fix_aspect=False, ax=ax)
ax.add_collection3d(m.drawcoastlines(linewidth=0.25))
ax.add_collection3d(m.drawcountries(linewidth=0.25))
ax.add_collection3d(m.drawstates(linewidth=0.25))
ax.view_init(azim = 230, elev = 15)
ax.set_xlabel(u'Longitude (°E)', labelpad=10)
ax.set_ylabel(u'Latitude (°N)', labelpad=10)
ax.set_zlabel(u'Altitude (ft)', labelpad=20)

# values to plot - change as needed. Plots 2 dots, one at elevation 0 and another 100.
# also draws a line between the two.
x, y = m(-85.4808, 32.6099)
ax.plot3D([x, x], [y, y], [0, 100], color = 'green', lw = 0.5)
ax.scatter3D(x, y, 100, s = 5, c = 'k', zorder = 4)
ax.scatter3D(x, y, 0, s = 2, c = 'k', zorder = 4)

ax.set_zlim(0., 400.)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.