【发布时间】:2020-11-10 07:04:11
【问题描述】:
我正在尝试绘制加利福尼亚州代表错过选票的百分比,但要注意根据政党进行着色。我可以在同一个图上使用 GeoPandas 绘制两个颜色图,但我无法让两个颜色图都显示在图例上。
fig, ax = plt.subplots(figsize=(10, 6))
california = merged[merged['STATENAME'] == 'California']
rs = california[california['party'] == 'R']
ds = california[california['party'] == 'D']
# set the value column that will be visualised
variable = 'PCT'
# create map
rs.plot(column=variable, ax=ax, legend=False, cmap='Reds', scheme='quantiles', k=7)
ds.plot(column=variable, ax=ax, legend=True, cmap='Blues', scheme='quantiles', k=7)
生成的图如下所示:
【问题讨论】:
-
为什么你在 rs 图上有 legend=False?你能提供给我们数据吗?
-
能否将 legend=False 更改为 legend=True 并重新运行脚本。
-
@squeezer44 将两行都设置为 Legend=True 不会改变任何东西。当我发布此内容时,我正在使用其中一个或另一个来查看它是否可以工作,但我忘记了将其更改回来。这是我用来生成加利福尼亚图的示例数据:drive.google.com/file/d/1lp5CeMyC88cFBRRxfOmAevo6UHeDU0za/…
标签: python pandas matplotlib geopandas