简体   繁体   English

如何使用 pysal 或 geopandas 并排 plot 两张地图?

[英]How to plot two maps side by side using pysal or geopandas?

I want to plot two tematic maps side by side to compare then.我想把 plot 两个 tematic 地图并排比较。 I am using geopandas to plot the maps and pysal to generate the maps from spatial analysis.我正在使用 geopandas 来 plot 地图和 pysal 从空间分析中生成地图。

You can create the subplots structure with matplotlib, and then add the plots with geopandas/pysal to the specific subplot: 您可以使用matplotlib创建子图结构,然后将具有geopandas / pysal的图添加到特定子图:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(ncols=2)
# add geopandas plot to left subplot
geodataframe.plot(..., ax=axes[0])
# add pysal plot to right subplot using `axes[1]`
import folium
import folium.plugins

m = folium.plugins.DualMap(location=(52.1, 5.1), tiles='cartodbpositron', zoom_start=8)

fg_both = folium.FeatureGroup(name='markers_both').add_to(m)
fg_1 = folium.FeatureGroup(name='markers_1').add_to(m.m1)
fg_2 = folium.FeatureGroup(name='markers_2').add_to(m.m2)

icon_red = folium.Icon(color='red')
folium.Marker((52.0, 5.0), tooltip='both', icon=icon_red).add_to(fg_both)
folium.Marker((52.4, 5.0), tooltip='1').add_to(fg_1)
folium.Marker((52.0, 5.4), tooltip='2').add_to(fg_2)

folium.LayerControl(collapsed=False).add_to(m)
m

#output #输出

在此处输入图像描述

In order to get two geopandas maps side by side, you can write: 为了并排获得两个geopandas地图,您可以编写:

fig, (ax1,ax2) = plt.subplots(nrows=1, ncols=2, figsize=(20, 16))
ax1 = geodataframe.plot(ax=ax1, column='obs', legend=True)
ax2 = geodataframe.plot(ax=ax2, column='pred', legend=True)

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

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