我想创建一个分组条形图,显示每组的中位数和平均值。我还使用动画帧来显示每个中位数和均值如何根据 ubi 数量而变化。
我想对这些条形图进行分组,以便它显示每个组的中位数和平均值及其变化方式。
这是我的代码,但我不知道如何对它们进行分组。
import pandas as pd
import plotly.express as px
summary_med = pd.read_csv('https://github.com/ngpsu22/indigenous-peoples-day/raw/main/native_medians_means')
fig = px.bar(summary_med, x = 'race', y='med_resources_per_person',
animation_frame='monthly_ubi', range_y=[0,25_000],
labels={
"med_resources_per_person": "Median resources per person",
"race": "Race",
"monthly_ubi": "Monthly UBI",
"native": "Native",
"non_native": "Non-native"
},
title="Tax funded UBI and median resources per person",
color='race',
text='med_resources_per_person',
height=900, width=800,
color_discrete_map={'native': '#5886a5',
'non_native': '#5886a5'})
fig.update_traces(texttemplate='$%{text}')
fig.update_layout(showlegend=False, yaxis_tickprefix='$')
fig.show()
一只斗牛犬
肥皂起泡泡
相关分类