I understand now
I’m not sure if there is a more straightforward way of adding the 1 master x-axis title with plotly express, I think probably not at the moment although I’ll admit that I don’t use plotly express that often.
As far the the mismatched fonts go, the way to address this would be to edit the font properties of the annotation to match with the default settings with a attribute like this:
font=dict(
family="Courier New, monospace",
size=16,
color="#ffffff"
)
Also see:
This will work assuming you know the default text properties which is used for the y-axis label
Frankly, after a few minutes trying to match the y and x-axis formatting (and failing) it’s less effort to just use a custom annotation for both the x and y-axis titles
For reference I’ll attach a reproducible code snippet here of my work.
# #############################################################################
# Import Modules
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go
# #############################################################################
# Import a default dataframe from plotly
df = px.data.tips()
# #############################################################################
# Set up figure with plotly express
fig = px.scatter(
df,
x="total_bill",
y="tip",
facet_col='day')
# #############################################################################
# I needed these line to get rid of the default x-axis labels
fig.layout["xaxis"].title.text = ""
fig.layout["xaxis2"].title.text = ""
fig.layout["xaxis3"].title.text = ""
fig.layout["xaxis4"].title.text = ""
# #############################################################################
# IMPORTANT | Set the global font properties of the figure
fig.update_layout(
font=dict(
family="Time New Roman",
size=18,
color="red"))
fig.update_layout(
annotations=[
go.layout.Annotation(
{
'showarrow': False,
'text': 'tip',
'x': 0.5,
'xanchor': 'center',
'xref': 'paper',
'y': 0,
'yanchor': 'top',
'yref': 'paper',
'yshift': -30,
"font": dict(
# family="Courier New, monospace",
size=18,
# color="#ffffff"
),
})
]
)
fig.show()