繁体   English   中英

用matplotlib熊猫创建海洋情节

[英]create seaborn plot with pandas of matplotlib

我正在努力用熊猫或matplotlib(重新)创建一个海洋情节。

数据帧:

wage = pd.melt(pd.read_html('https://en.wikipedia.org/wiki/List_of_countries_by_average_wage')[8].iloc[:5],
               id_vars=['Country'],var_name='Year', value_name='Wage')
print(wage.sample(n=7))

结果:

          Country  Year   Wage
29    Netherlands  2013  52808
38  United States  2015  60692
4     Netherlands  2000  47596
9     Netherlands  2005  49939
23  United States  2012  58669
46    Switzerland  2017  62283
12        Iceland  2010  44558

使用seaborn的情节很简单:

fig, ax = plt.subplots(figsize=(15, 7))
sns.lineplot(x='Year', y='Wage', hue='Country', linewidth=3, data=wage, ax=ax)
ax.set_title('Development of average annual wages 2000–2017 (US$ PPP)', fontsize=16)
plt.show()

在此处输入图片说明

但是我想用熊猫使用wage.plot()matplotlib创建相同的情节。 有什么建议怎么做?

您可以循环wage['Country']

fig, ax = plt.subplots()
for c, d in wage.groupby('Country'):
    ax.plot(d.Year, d.Wage, label=c)

plt.legend()

plt.show()

这使:

在此处输入图片说明

暂无
暂无

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

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