【问题标题】:Is there a way to overlay a bar chart (matplotlib) onto a map (geopandas)?有没有办法将条形图(matplotlib)叠加到地图(geopandas)上?
【发布时间】:2021-01-24 02:05:51
【问题描述】:

我这样绘制地图。如何用条形图覆盖它?

import geopandas as gpd
import matplotlib.pyplot as plt

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
ax = world.plot()
plt.show()

应该和我在网上找到的这张图差不多:

【问题讨论】:

  • 我认为这是可能的,但我不明白你如何期望情节重叠。你能提供一个直观的例子吗?
  • 感谢您的回复!我编辑了我的问题并提供了一个示例图片。

标签: python matplotlib geopandas


【解决方案1】:

将两个图叠加起来很容易,很难将条形图精确地放在一个点坐标上。我只用一个条形图制作了这个例子,但这只是一个近似值:

import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
fig = plt.figure()
ax_map = fig.add_axes([0, 0, 1, 1])
world.plot(ax=ax_map)
lat, lon = 19.432608, -99.133208
ax_bar = fig.add_axes([0.5*(1+lon/180) , 0.5*(1+lat/90) , 0.05, 0.05])
ax_bar.bar([1, 2, 3], [1, 2, 3], color=['C1', 'C2', 'C3'])
ax_bar.set_axis_off()
plt.show()

【讨论】:

猜你喜欢
  • 2015-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-26
相关资源
最近更新 更多