How to center title in Plotly

In Plotly, you can center the title of a plot by setting the title.x attribute to 0.5 and the title.xref attribute to “paper”.

Here’s an example of how you can center the title of a plot in Plotly:

import as px

# Create a sample plot
df =
fig = px.scatter(df, x="total_bill", y="tip", color="smoker")

# Center the title
        text="Tips Dataset",

# Show the plot

In this example, we use Plotly Express to create a scatter plot of the tips dataset, and then we update the plot layout to center the title. The text attribute sets the title text, font sets the font size, x sets the title x position, and xref sets the x reference. Finally, we show the plot using the show method of the figure object.

See also  How to create a title with multiple lines in Plotly