简体   繁体   English

用matplotlib熊猫创建海洋情节

[英]create seaborn plot with pandas of matplotlib

I'm struggling to (re)create a seaborn plot with pandas or matplotlib. 我正在努力用熊猫或matplotlib(重新)创建一个海洋情节。

DataFrame: 数据帧:

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))

Result: 结果:

          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

The plot using seaborn is easy: 使用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()

在此处输入图片说明

But I would like to create the same plot with pandas using wage.plot() or with matplotlib . 但是我想用熊猫使用wage.plot()matplotlib创建相同的情节。 Any suggestions how to do that? 有什么建议怎么做?

You can loop over the wage['Country'] : 您可以循环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()

which gives: 这使:

在此处输入图片说明

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

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