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. Here we are going to create a scatter plot using dataframe. For this, we will create dataframe from a given dataset. Output: 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) Output:Creating a regular plot so that the difference can be apparent
Python3
# import librariesimport plotly.express as pximport pandas as pd # read datasetdata = pd.read_csv("bestsellers.csv") fig = px.scatter(data, x="Year", y="Price", color="Genre") fig.show()
Hide legend in plotly express
Python3
# import librariesimport plotly.express as pximport pandas as pd # read datasetdata = pd.read_csv("bestsellers.csv") fig = px.scatter(data, x="Year", y="Price", color="Genre")fig.update_layout(showlegend = False) fig.show()




