【发布时间】:2022-08-09 21:27:42
【问题描述】:
我正在尝试比较两组伦敦 Airbnb 数据。我想要一种优雅的方式在两个子图上绘制伦敦 shapefile,然后将不同的数据叠加为每个地图上的点。我的 shapefile 来自这里:
londonshp = gpd.read_file(\"statistical-gis-boundaries london\\ESRI\\London_Borough_Excluding_MHW.shp\")
londonshp = londonshp.to_crs(4326)`
这是绘制地图的代码:
fig, axes = plt.subplots(ncols=2, figsize = (12,16))
#entire home/apt on left
axes[0].set_aspect(\'equal\')
londonshp.plot(ax = axes[0],
color = \'#e0e1dd\',
edgecolor = \'#1c1c1c\')
axes[0].scatter(entirehomedf.longitude,
entirehomedf.latitude,
s = 1,
c = \'#2ec4b6\',
marker = \'.\')
axes[0].set_yticklabels([])
axes[0].set_xticklabels([])
axes[0].set_title(\"Entire Homes/Apts\")
#private room on right
axes[1].set_aspect(\'equal\')
londonshp.plot(ax = axes[1],
color = \'#e0e1dd\',
edgecolor = \'#1c1c1c\')
axes[1].scatter(privateroomdf.longitude,
privateroomdf.latitude,
s = 1,
c = \'#ff9f1c\')
axes[1].set_yticklabels([])
axes[1].set_xticklabels([])
axes[1].set_title(\"Private Rooms\")
结果:
我的代码工作正常,但似乎不优雅。
- 在每个子图上手动绘制 shapefile 仅适用于两个子图,但不适用于大量子图。我想有一种更快的方法可以自动完成(例如循环?)
- 每个子图上的一些散点图特征(如标记形状/大小)相同。我确信有一种更好的方法可以为整个图形设置这些特征,然后分别编辑每个子图各自的特征(如颜色)。
标签: python matplotlib plot shapefile subplot