【发布时间】:2018-03-24 14:24:15
【问题描述】:
对于我大学的一个项目,我想使用 Python 2.7 显示一个(德国)城市的地图,主要是道路,最后包括几个服务点的地理位置。我有 Python 的基本知识,但我觉得我无法访问为实现目标而需要执行的步骤。
我使用底图来限制城市所在的经度和纬度区域。然后我想使用 shapefile 来包含已提供的道路,但我收到错误消息“RuntimeError:无法将单个艺术家放入多个图中”。尽管搜索我找不到解决方案。这是我使用的代码:
import matplotlib.pyplot as plt
import matplotlib.cm
import numpy as np
import shapefile as shp
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.collections import LineCollection
from matplotlib.collections import PolyCollection
from matplotlib.colors import Normalize
fig, ax=plt.subplots(figsize=(10,20))
m = Basemap(resolution='c', # c, l, i, h, f or None
projection='merc',
#lat lowleft: llcrnrlon, lon low right llcrnrlat
#lat upleft urcrnrlon=47.81,, lon up right urcrnrlat=10.5
llcrnrlon=8.45195, llcrnrlat=49.477816, urcrnrlon=8.491432, urcrnrlat=49.50117)
drawmapboundary(fill_color='aqua')
m.fillcontinents(color='firebrick')
m.drawrivers(color='aqua')
m.drawcoastlines()
plt.show()
m.readshapefile('roads', 'roads')
然后我得到了 Google Maps API,但在我看来,我不能用它们来分发地图。另外,加载 pygmaps 包装器崩溃:“ImportError: No module named pygmaps”,反正我不知道怎么用。
这里有人知道我可以采取哪些步骤来实现我的目标吗?我将非常感谢您的建议。提前致谢!
【问题讨论】:
-
请分享您使用的代码,这将澄清您的问题。
-
我在原帖中编辑过
标签: python google-maps-api-3 shapefile matplotlib-basemap