Plotly offers extensive customization options for your plots, including adjusting the title font size. This guide demonstrates two methods to achieve this: using the layout argument and the update_layout method.
Method 1: Using the layout argument
To directly change the title font size at the time of plot creation, include a title_font size specification within the layout dictionary. This is a dictionary that allows you to modify various aspects of your plot’s layout. To set the title font size to 24, for example:
import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", title="Iris Dataset", layout=dict(title_font=dict(size=24))) fig.show()
This example creates a scatter plot from the Iris dataset with a title font size of 24.
Method 2: Using the update_layout method
The update_layout method provides a flexible approach for tweaking your plot’s appearance, including the title font size, after the plot has been created. You can specify the title font size by passing a dictionary to the title_font argument, like so:
import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species") fig.update_layout(title="Iris Dataset", title_font={"size": 24}) fig.show()
In this example, the update_layout method is used to set the title font size to 24 for a scatter plot of the Iris dataset.
These methods provide flexibility in customizing the appearance of your Plotly plots, ensuring they meet your presentation or publication standards.