A radiation dose simulation gave the [following organ doses:][1]
I would like to use Python - Plotly to make a grouped bar chart with the five highest organ dose values from each age group columns '0', '1', '5', '10', and '15'.
The x-axis should show those five organs from each age column that gets the highest dose.
I have started with finding the five largest for the '0' age group and make a bar graph:
import pandas as pd
import plotl.express as px
df = pd.read_csv('data_org_dos.csv')
data = df.set_index('Organ')['0'].nlargest(5)
fig = px.bar(data)
fig.show()
How do I make a grouped bar graph with all the ages '0', '1', '5', '10' and '15' presented in the same graph?
Following @Timeless answer I could change the code to produce the grouped bar chart I aimed for:
import pandas as pd
import plotly.graph_objs as go
df = pd.read_csv("data_org_dos.csv")
labels = df.columns.map(lambda x: "Age: " x)[1:]
fig = go.Figure()
for idx, age in enumerate(labels):
data = df.set_index('Organ')[age.split()[-1]].nlargest(5).reset_index()
fig.add_trace(go.Bar(x=data['Organ'], y=data[age.split()[-1]], name=age))
fig.update_xaxes(title_text='Organ')
fig.update_yaxes(title_text='E [mSv]')
fig.update_layout(
font=dict(
size=18
)
)
fig.show()
[ see image link][2]
[1]: https://www.dropbox.com/s/qux9v9ubp5cskl6/data_org_dos.csv?dl=0
[2]: https://i.stack.imgur.com/iiEAt.png
CodePudding user response: