简体   繁体   English

如何使用 pandas / geopandas 增加 plot 的 bin 数量?

[英]How can I increase the number of bins for my plot using pandas / geopandas?

Currently a lot of my data is showing with a huge range of values in one bin - all data goes from 0 to 1.31, but my top bin colour is holding 0.15 to 1.31.目前,我的很多数据都在一个 bin 中显示了很大范围的值 - 所有数据都从 0 到 1.31,但我的顶部 bin 颜色保持 0.15 到 1.31。

This is my code to plot:这是我对 plot 的代码:

merged.plot(column='vaccinations_per_person', scheme="quantiles", figsize=(25, 20),
           legend=True, norm=colour, cmap='Oranges', missing_kwds = 
           dict(color = "lightgrey", label = "No Data"))
plt.title('Vaccinations per Person',fontsize=25)

And this is my legend:这是我的传奇:

我的传奇截图

You can do it easily by specifying the number of bins as k=10 (if you want 10).您可以通过将箱数指定为k=10 (如果您想要 10)轻松完成此操作。

 merged.plot(column='vaccinations_per_person', scheme="quantiles", figsize=(25, 20),
           legend=True, norm=colour, cmap='Oranges', missing_kwds = 
           dict(color = "lightgrey", label = "No Data"), k=10)
  • use a colormap with scatter and there is no limit to bins使用带有 scatter 的颜色图,并且 bin 没有限制
import pandas as pd
import io, requests, matplotlib

dfraw = pd.read_csv(io.StringIO(requests.get("https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/vaccinations.csv").text))

cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["aqua","limegreen","green"])

dfraw["date"] = pd.to_datetime(dfraw["date"])
dfp = (dfraw.sort_values(["iso_code","date"])
 .groupby(["iso_code"], as_index=False).last()
 .loc[:,["iso_code","people_vaccinated_per_hundred"]]
 .dropna()
 .plot(kind="scatter", x="iso_code", y="people_vaccinated_per_hundred", c="people_vaccinated_per_hundred", cmap=cmap)
)

在此处输入图像描述

Using geopandas and folium with the same colormap and a bit more preparation you get to:使用具有相同颜色图的geopandasfolium并进行更多准备: 在此处输入图像描述

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

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