如何将下面的dataframe-info绘制到geopandas地图上?气泡大小应取决于案例编号!
import geopandas
import geoplot
import pandas
d = {"Germany": 5, "United Kingdom" : 3, "Finland" : 1, "United States of America" : 4}
df = pandas.DataFrame.from_dict(d,orient='index')
df.columns = ["Cases"]
def WorldCaseMap():
world = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
ex = geoplot.polyplot(world)
WorldCaseMap()
我不确定geopandas
是否会轻松地提供气泡图。他们最好的例子是一个choropleth:
gpd_per_person = world['gdp_md_est'] / world['pop_est']
scheme = mapclassify.Quantiles(gpd_per_person, k=5)
# Note: this code sample requires geoplot>=0.4.0.
geoplot.choropleth(
world, hue=gpd_per_person, scheme=scheme,
cmap='Greens', figsize=(8, 4)
)
我在这里使用geopandas
找到了另一个气泡图示例:https://residentmario.github.io/geoplot/gallery/plot_usa_city_elevations.html但是我更喜欢该示例的外观。 (请参见下文)。
否则,请查看plotly的示例,它们具有气泡图:https://plot.ly/python/bubble-maps/
制作第二个包含质心几何形状的df并将其绘制在第一个df上。下面的工作示例。
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
centroids = world.copy()
centroids.geometry = world.centroid
centroids['size'] = centroids['pop_est'] / 1000000 # to get reasonable plotable number
ax = world.plot(facecolor='w', edgecolor='k')
centroids.plot(markersize='size', ax=ax)