Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

plotly loop in loop #173

Description

@ilyinss

Hello. At first, thank you for Plotly. Its great.
Help me, if you can.

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.head()

# here my plotly-try:

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

for i in test.index.levels[0]:
    local_df = test.loc[test.index.get_level_values(0)==i]
    trace = go.Bar(x = local_df.index.get_level_values(1),
                  y = local_df.values)
    test_fig.add_trace(trace)
    
test_fig.show()

plotly shows 3 subplots, but 2 of subplots are empty.
what am i doing wrong?

i would like to get 3 subplots: for each month in dataset

stackoverflow cant helps me.

thank you

p.s. sorry for my english speech - its not my natural

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions