D4w1d
D4w1d

Reputation: 125

How to show 3 box plots from 3 columns from one dataframe

My problem is I can't display 3 boxplots on one plotly space. When I try so, I see only blank space, without any plot. Giving one of the columns name to "y" argument of px.box function, showing only one box. But I want 3 on one space.

def filter_df(df):
    original_list = df.values.tolist()
    iqr_list = IQR_outliners(df)
    zscore_list = zscore_outliners(df)
    
    dc = {'Original':original_list,'IQR':iqr_list, 'Z-Score':zscore_list}
    df_new = pd.DataFrame.from_dict(dc, orient='index')
    df_new = df_new.transpose()
    print(df_new)
    
    fig = px.box(df_new)
    fig.show()

filter_df(df1.holeDiameter)

This is dataframe I want to plot and below the plotly blank space:

      Original    IQR  Z-Score
0          NaN  0.120    0.120
1          NaN  0.101    0.101
2        0.120  0.100    0.100
3        0.101  0.100    0.100
4        0.100  0.100    0.100
...        ...    ...      ...
1430     0.100    NaN      NaN
1431     0.100    NaN      NaN
1432     0.100    NaN      NaN
1433     0.100    NaN      NaN
1434     0.100    NaN      NaN

[1435 rows x 3 columns]

plotly space where should be boxes

Any ideas?

Upvotes: 1

Views: 688

Answers (1)

D4w1d
D4w1d

Reputation: 125

Okay, I made it!

import plotly.graph_objects as go

def filter_df(df):
    original_list = df.values.tolist()
    iqr_list = IQR_outliners(df)
    zscore_list = zscore_outliners(df)
    
    dc = {'Original':original_list,'IQR':iqr_list, 'Z-Score':zscore_list}
    df_new = pd.DataFrame.from_dict(dc, orient='index')
    df_new = df_new.transpose()
    
    print(df_new)

    fig = go.Figure()

    for col in df_new:
        fig.add_trace(go.Box(y=df_new[col].values, name=df_new[col].name))
  
    fig.show()

filter_df(df1.holeDiameter)

plots

Upvotes: 1

Related Questions