So I want to customise my chart axes titles
So my graphs are printing out the correct data but for one of the graphs the axis does not match the hover text.
df["M "] = df["Date_Modified"]
fig = px.bar(df, x = "M ", y = "Count", facet_row = "Entity", color = "Entity")
fig.update_traces(marker_line_width=0, opacity=1)
fig.update_layout(title=(option.title() + " by company"), yaxis_zeroline=False, xaxis_zeroline=False)
fig.update_xaxes(title_text = "")
fig.show()

So I want to get rid of the entity axis and also make the count be only displayed once

I want the Facet title for the second image be more clean so just Feb19 or Mar 19 and not with an = sign
UPDATE: as of plotly version 4.2 in October 2019, the following usage of for_each_annotation is recommended by the docs at https://plotly.com/python/facet-plots/#customize-subplot-figure-titles
import plotly.express as px
fig = px.scatter(px.data.tips(), x="total_bill", y="tip", facet_row="sex")
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
fig.show()
The facet titles here are stored as annotations in the figure, under fig.layout.annotations so you can edit them directly in there with e.g. fig.layout.annotations[0].text = "new text"
Here's a simple loop to just keep the part after the = sign:
import plotly.express as px
fig = px.scatter(px.data.tips(), x="total_bill", y="tip", facet_row="sex")
for annotation in fig.layout.annotations:
annotation.text = annotation.text.split("=")[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