Quantcast
Viewing all articles
Browse latest Browse all 14069

Plotly wrong subplot format

I have faced a problem with wrong format of one of the subplots using Plotly.

Problem with MonthlyCharges_Category, which has format of

['starter', 'standard', 'advanced']Categories (3, object): ['starter'< 'standard'< 'advanced']

But for some reason the graph build code takes numeric values somehow. For TotalCharges_category it's okay for some reason.

Target_col = "Target"nrows = (len(data.columns) - 1) // 4 + 1ncols = min(len(data.columns), 4)fig = make_subplots(rows=nrows, cols=ncols, subplot_titles=data.columns.drop(target_col), vertical_spacing=0.1)for i, col in enumerate(data.columns.drop(target_col)):    row = i // ncols + 1    col = i % ncols + 1    trace1 = go.Histogram(x=data[data[target_col] == 0][data.columns[i]], name="0", marker_color='blue',\                          opacity=0.5, showlegend=False)    trace2 = go.Histogram(x=data[data[target_col] == 1][data.columns[i]], name="1", marker_color='red', opacity=0.5,\                         showlegend=False)    fig.add_trace(trace1, row=row, col=col)    fig.add_trace(trace2, row=row, col=col)    fig.update_xaxes(row=row, col=col, title_font=dict(size=12), tickfont=dict(size=10))    fig.update_traces(showlegend=False, selector=dict(type='histogram'))fig.update_layout(height=1200, width=1000, title_text="Class Balance")fig.show()

I have tried few ways to get rid (checking values, format of column etc), but nothing helps.

Thanks in advance.

Image may be NSFW.
Clik here to view.
main plot

Structure of data looks something like this with different columns with 2-3 categorical options.I delete column which has float values 'MonthlyCharges' as well before the plotting.

MonthlyCharges_categoryTotalCharges_categoryClientAgeDays
starterstandard145
advancedstarter1492

printing out MonthlyCharges_category gives

0        starter1       standard2       standard3       standard4       advanced          ...   7038    advanced7039    advanced7040     starter7041    advanced7042    advancedName: MonthlyCharges_category, Length: 7043, dtype: categoryCategories (4, object): ['no'< 'starter'< 'standard'< 'advanced']

Viewing all articles
Browse latest Browse all 14069

Trending Articles