0

not sure if this is correct medium, but i am having trouble plotting this simple data:

enter image description here enter image description here

how do i get the graph below - aplogies for this poor picture.

basically i want it stacked with the risk label being the legend, but the predicted and actual side by side for each year.. how can i achieve this in pandas? btw this is a pandas dataframe

e.g.

df_partial = df[['year','risk','predicted','actual']]
grouped = df_partial.groupby(['year','risk']).sum()[['predicted','actual']]
grouped.plot(kind='bar') 

it does not give me what i would like to see

import plotly.graph_objs as go
df = df.melt(id_vars=["year", "risk"], value_vars=["predicted", "actual"])
fig = go.Figure()

for risk in ["low", "medium", "high"]:
    tmp_df = df.query(f"risk == '{risk}'")
    fig.add_trace(
        go.Bar(
            x=[tmp_df["year"], tmp_df["variable"]], y=tmp_df["value"], name=risk,
        )
    )
    
fig.update_layout(barmode="stack", height=400, width=800, margin=dict(b=60, t=20, l=20, r=20))
fig.show()

however i get :

enter image description here

how do i remove these faint lines? i've tried opacity does now work

Kasra Manshaei
  • 6,502
  • 1
  • 20
  • 45
Maths12
  • 496
  • 5
  • 14
  • Have a look at [plotly](https://plotly.com/python/bar-charts/#stacked-bar-chart) – null Jun 25 '20 at 20:59
  • @null how can i do thid using plotly - i have some code above using it but i want a bar chart for predicted side by side each year – Maths12 Jun 26 '20 at 08:07
  • You can try this question on StackOverflow. I believe you will get a quick and better answer – 10xAI Jun 26 '20 at 13:10

0 Answers0