3

Please help, i need get 3 subplots for one month in subplot. in my dataframe, i get multiindex (months and names) and values column i want to put this data in loop and draw Plotly-charts.
Please, help if you can. Thank you.

import pandas as pd
from plotly.subplots import make_subplots
import plotly.graph_objects as go

my_months = [9,9,9,10,10,10,11,11,11]
my_vls = [10, 20, 30, 20, 15, 25, 20, 30, 20]
my_names = ['one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three',]
test = pd.DataFrame(zip(my_months, my_names, my_vls), columns=['month','names', 'values'])
test = test.groupby(['month', 'names']).sum()

test_fig = make_subplots(
    rows = len(test.index.levels[0]),
    cols = 1)

months = test.index.levels[0].unique()

for i, month in months:
    vals = test.loc[test.index.get_level_values(0)==month]['values'].unique()
    for j in local_df.index.levels[1]:
        local_df_2 = local_df.loc[local_df.index.get_level_values(1)==j]
        test_fig.append_trace(
            go.Bar(
                x = local_df_2.index.get_level_values(1),
                y = local_df_2.values), 
            row=i+1, 
            col=1)
        
test_fig.show()

i find some SO-links, probably it helps:
first
second

1 Answer 1

0

solution is very simple:

y = local_df_2.values[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.