I have a dataframe like this in Python:
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.figure_factory as ff
np.random.seed(1234)
df = pd.DataFrame(np.random.randn(10, 4),
columns=['Col1', 'Col2', 'Col3', 'Col4'])
df['id'] = range(1, len(df.index)+1)
df
# making a long dataframe
# sorting the dataframe by value (i.e. randomly)
long_df = df.melt(id_vars = ['id'],
var_name = 'type',
value_name = 'value').sort_values(by='value')
long_df['id'] = range(1, len(long_df.index)+1)
long_df.head()
long_df = long_df.drop(long_df[long_df.id < 10].index)
long_df.head()
long_df['type'].value_counts().sort_index()
and I created a boxplot using these commands:
box_plot= ff.create_facet_grid(
long_df,
x = 'type',
y = 'value',
trace_type = 'box',
color_name = 'type',
color_is_cat = True,
width = 1000,
ggplot2 = False,
showlegend = False,
)
box_plot.show()
I there any way to set the box width proportional to the number of rows in that category? (similar to the way R does). I expect the box widths to be in this order (from slim to fat): col2(n=5)--> col4(n=7) --> col1(n=9) --> col3(n=10)