如何在Seaborn创建一个区域图?

问题描述 投票:-1回答:1

有没有办法在Seaborn创建一个区域图。我检查了文档,但我无法找到它。

这是我要绘制的数据。

year_countries.head()
Out[19]: 
state_code   China  France  Japan  Russia  United States
launch_year                                             
1957             0       0      0       2              1
1958             0       0      0       5             22
1959             0       0      0       4             18
1960             0       0      0       8             29
1961             0       0      0       9             41

我用这段代码创建了一个线图 -

sns.relplot(data=year_countries, kind='line',
            height=7, aspect=1.3,linestyle='solid')

plt.xlabel('Lanuch Year', fontsize=15)
plt.ylabel('Number of Launches', fontsize=15)
plt.title('Space Launches By Country',fontsize=17)

plt.show()

但使用折线图时,情节并不是那么清楚 - Plot fig

也无法使行显示为Solid并根据值按降序对图例进行排序。

谁能帮我这个?

python pandas seaborn
1个回答
3
投票

使用Seaborn风格的Pandas区域情节怎么样?

另外,你需要自己对图例进行排序,我从qazxsw poi中获取了示例代码。

here

输出:

plt.style.use('seaborn') year_countries.plot.area() plt.xlabel('Launch Year', fontsize=15) plt.ylabel('Number of Launches', fontsize=15) plt.title('Space Launches By Country',fontsize=17) ax = plt.gca() handles, labels = ax.get_legend_handles_labels() labels, handles = zip(*sorted(zip(labels, handles), key=lambda t: t[0], reverse=True)) ax.legend(handles, labels) plt.show()

© www.soinside.com 2019 - 2024. All rights reserved.