--- jupyter: jupytext: notebook_metadata_filter: all text_representation: extension: .md format_name: markdown format_version: '1.3' jupytext_version: 1.14.1 kernelspec: display_name: Python 3 language: python name: python3 language_info: codemirror_mode: name: ipython version: 3 file_extension: .py mimetype: text/x-python name: python nbconvert_exporter: python pygments_lexer: ipython3 version: 3.8.8 plotly: description: How to set the global font, title, legend-entries, and axis-titles in python. display_as: file_settings language: python layout: base name: Setting the Font, Title, Legend Entries, and Axis Titles order: 13 permalink: python/figure-labels/ redirect_from: python/font/ thumbnail: thumbnail/figure-labels.png --- ### Automatic Labelling with Plotly Express [Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/). When using Plotly Express, your axes and legend are automatically labelled, and it's easy to override the automation for a customized figure using the `labels` keyword argument. The title of your figure is up to you though! Here's a figure with automatic labels and then the same figure with overridden labels. Note the fact that when overriding labels, the axes, legend title *and hover labels* reflect the specified labels automatically. ```python import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_length", y="sepal_width", color="species", title="Automatic Labels Based on Data Frame Column Names") fig.show() ``` ```python import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_length", y="sepal_width", color="species", labels={ "sepal_length": "Sepal Length (cm)", "sepal_width": "Sepal Width (cm)", "species": "Species of Iris" }, title="Manually Specified Labels") fig.show() ``` ### Global and Local Font Specification You can set the figure-wide font with the `layout.font` attribute, which will apply to all titles and tick labels, but this can be overridden for specific plot items like individual axes and legend titles etc. In the following figure, we set the figure-wide font to Courier New in blue, and then override this for certain parts of the figure. ```python import plotly.express as px df = px.data.iris() fig = px.scatter(df, x="sepal_length", y="sepal_width", color="species", title="Playing with Fonts") fig.update_layout( font_family="Courier New", font_color="blue", title_font_family="Times New Roman", title_font_color="red", legend_title_font_color="green" ) fig.update_xaxes(title_font_family="Arial") fig.show() ``` ### Fonts and Labels in Dash [Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash dash-daq`, click "Download" to get the code and run `python app.py`. Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with Dash Enterprise.** ```python hide_code=true from IPython.display import IFrame snippet_url = 'https://python-docs-dash-snippets.herokuapp.com/python-docs-dash-snippets/' IFrame(snippet_url + 'figure-labels', width='100%', height=1200) ```
Sign up for Dash Club → Free cheat sheets plus updates from Chris Parmer and Adam Schroeder delivered to your inbox every two months. Includes tips and tricks, community apps, and deep dives into the Dash architecture. Join now.