pythonbook/实例学习plotly/Express line.py

38 lines
993 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import plotly.express as px
import pandas
df = px.data.gapminder()
df1 = df.query("country == 'United States' or continent == 'Asia'")
# 根据大陆对数据进行分组并计算每个大陆的人均GDP平均值
gdpPercap_summary = df.groupby('continent')[['gdpPercap','lifeExp']].mean().reset_index()
# 显示结果
print(gdpPercap_summary)
print(df1.columns)
fig = px.line(df1,
x="year",
y="lifeExp",
# color="continent",
title="A Plotly Express Figure",
markers=True,
# symbol="continent",
line_shape="linear"
)
# ['linear', 'hv', 'vh', 'hvh', 'vhv']
df2 = df.query("continent == 'Oceania'")
fig = px.bar(df2,
x="year",
y="pop",
color="country",
barmode="group"
)
df = px.data.tips()
print(df.columns)
fig = px.pie(df,values="total_bill",names="day"
)
fig.show()