When using plotly express for histograms with a marginal subplot and changing the axis-titles i have the problem that the axis titles are shown twice.

See for example this code:
import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", marginal="violin")
fig.update_xaxes(title_text='x-axis')
fig.update_yaxes(title_text='y-axis')
fig.show()
what can i do that the axis titles are shown only once?
You need to edit only the axes for the subplot you want. One way to do that is generate a grid space using the old plotly figures syntax. However, because you're using express - the subplots are generated automatically and what they are called is buried in the figure information. However, because everything in plotly is really a dictionary, you can call
fig.__dict__
and find what everything is called (for a complicated figure). In general, it seems that bottom left figure (in this case, and in most cases, this is your main figure) is in row 1, col 1, so you can do something like:
import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="total_bill", marginal="violin")
fig.update_yaxes(title_text='y-axis',row=1, col=1)
fig.update_xaxes(title_text='x-axis',row=1, col=1)
fig.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With