How to move a boxplot inside a Figure?

hi @christek
Thanks for sharing the data.
I used the multiple axes section of the docs to build your graph. Would this work for you?

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


df = pd.read_csv('data.csv')
df['TotalCharges'] = pd.to_numeric(df.TotalCharges, errors='coerce')
df.dropna(inplace=True)


# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])

# Add traces
fig.add_trace(
    go.Box(y=df['MonthlyCharges'], name='Monthly Charges'),
    secondary_y=False,
)

fig.add_trace(
    go.Box(y=df['TotalCharges'], name='Total Charges'),
    secondary_y=True,
)
fig.show()

2 Likes