如何在Python Basemap上绘制值?

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

是否可以在底图上绘制值?

假设我有3个数据列表。

lat = [50.3, 62.1, 41.4, ...]
lon = [12.4, 14.3, 3.5, ...]
val = [3, 5.4, 7.4, ...]

我创建了一个简单的底图:

def create_map(ax=None, lllon=6.00, lllat=47.0, urlon=16.00, urlat=55.10):

    m = Basemap(llcrnrlon=lllon, llcrnrlat=lllat, \
            urcrnrlon=urlon, urcrnrlat=urlat, \
            resolution='h', \
            projection='tmerc', \
            lon_0=(lllon+urlon)/2, lat_0=(lllat+urlat)/2)

    m.drawcoastlines()
    m.drawcountries()
    m.drawrivers()

    return m

现在我想根据坐标在这张地图上绘制“val”列表的值:

m = create_map()

x, y = m(lon,lat)

m.scatter(x, y, val) # somthing like that

plt.show()

好吧,我已经发现底图无法绘制3d值,但有没有办法实现它?

python-3.x matplotlib-basemap
1个回答
0
投票

对你的第一个问题的简短,甜蜜和简单的回答是肯定的,你可以使用底图进行绘图(这里是documentation)。

如果你想在3d中绘图,有documentation解释如何使用Basemap绘图。这是一个简单的脚本,可以帮助您入门:

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.