Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python plotly different axis-title in subplot (marginal)

Tags:

python

plotly

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.

enter image description here

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?

like image 877
Egirus Ornila Avatar asked Apr 11 '26 21:04

Egirus Ornila


1 Answers

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()
like image 91
Kjell Avatar answered Apr 13 '26 10:04

Kjell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!