python plotly
作者:互联网
前述:https://blog.csdn.net/wxkhturfun/article/details/111464671
这里对参数进行一些分析。
1.条形图
首先执行一下:
import pandas as pd
import plotly.express as px
df = px.data.gapminder()
#fig = px.bar(df, x="continent", y="pop", color="continent",
# animation_frame="year", animation_group="country", range_y=[0,4000000000])
print(type(df))
print(df)
#fig.show()
会显示如下信息:
<class 'pandas.core.frame.DataFrame'>
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
... ... ... ... ... ... ... ... ...
1699 Zimbabwe Africa 1987 62.351 9216418 706.157306 ZWE 716
1700 Zimbabwe Africa 1992 60.377 10704340 693.420786 ZWE 716
1701 Zimbabwe Africa 1997 46.809 11404948 792.449960 ZWE 716
1702 Zimbabwe Africa 2002 39.989 11926563 672.038623 ZWE 716
1703 Zimbabwe Africa 2007 43.487 12311143 469.709298 ZWE 716
[1704 rows x 8 columns]
所以我们要创造一个数据类型为<class ‘pandas.core.frame.DataFrame’>的东西。
具体操作如下:
data = {
'x':['男','女','女','男','男'],
'z':['小明','小红','小芳','大黑','张三'],
'y':[20,21,25,24,29],
'cao':[0,255,128,1,1],
'a':['男','女','女','男','男'],}
df = pd.DataFrame(data,index=['one','two','three','four','five'],
columns=['x','z','y','cao','a'])
fig = px.bar(df, x="x", y="y", color="z",
animation_frame="cao", animation_group="a", range_y=[0,30])
fig.show()
可以看到x y color animation_frame animation_group的对象都只是字典的键(值),其值也不一定是数字,比如上例中的x、color就不是数字。
标签:...,Afghanistan,python,716,ZWE,df,animation,plotly 来源: https://blog.csdn.net/wxkhturfun/article/details/111479126