可视化神器Plotly绘制面积图

可视化神器Plotly绘制面积图

本文中介绍的是如何利用Plotly来绘制面积图,主要还是基于两种方法:

  • 基于plotly_express实现
  • 基于plotly.graph_objects实现

扩展阅读

Plotly的文章会形成连载系列,前面9篇Plotly可视化文章分别是:

导入库

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
复制代码

基于px实现

px.area creates a stacked area plot. Each filled area corresponds to one value of the column given by the line_group parameter.

px.area实现的是一个堆叠的面积图。每个填充的部分是通过给定的line_group参数来确定的,下面案例中采用的是自带的gdp数据集:

# 以GDP数据说明

gdp = px.data.gapminder()
gdp.head()
复制代码

.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}

.dataframe thead th {
text-align: right;
}

country continent year lifeExp pop gdpPercap iso_alpha iso_num
0 Afghanistan Asia 1952 28.801 8425333 779.445314 AFG 4
1 Afghanistan Asia 1957 30.332 9240934 820.853030 AFG 4
2 Afghanistan Asia 1962 31.997 10267083 853.100710 AFG 4
3 Afghanistan Asia 1967 34.020 11537966 836.197138 AFG 4
4 Afghanistan Asia 1972 36.088 13079460 739.981106 AFG 4
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享