Friday, October 10, 2025
HomeLanguagesHide legend in plotly express in Python?

Hide legend in plotly express in Python?

In this article, we will discuss how to hide legend in plotly express using Python.

Dataset in use: bestsellers4

The legend appears by default when variation in one object has to be depicted with reference to the other. Legend makes it easier to read a graph since it contains descriptions for the color code or keys used.

Creating a regular plot so that the difference can be apparent

Here we are going to create a scatter plot using dataframe. For this, we will create dataframe from a given dataset.

Python3




# import libraries
import plotly.express as px
import pandas as pd
  
# read dataset
data = pd.read_csv("bestsellers.csv")
  
fig = px.scatter(data, x="Year", y="Price", 
                 color="Genre")
  
fig.show()


Output:

Hide legend in plotly express

Now, to hide the legend, update_layout() function is called with showlegend argument set to false. This simple statement is enough to get the job done.

Syntax:

update_layout(showlegend=false)

Python3




# import libraries
import plotly.express as px
import pandas as pd
  
# read dataset
data = pd.read_csv("bestsellers.csv")
  
fig = px.scatter(data, x="Year", y="Price",
                 color="Genre")
fig.update_layout(showlegend = False)
  
fig.show()


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS