How to change the position of legend using Plotly Python? Last Updated : 28 Nov, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to change the position of the legend in Plotly using Python. 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. By default, the legend appears on the top right corner of the plot but outside of it, but it is possible to position them as per requirement. Let us first create a regular plot so that the difference can be apparent. Dataset Used: Click here Example: Regular plot 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: To position the legend we use the update_layout function with legend set to a dictionary that describes the attributes of a legend. anchor keys set position and x and y accommodate the margin with respect to axis. Syntax: update_layout(legend=dict(yanchor, y, xanchor, x)) By setting appropriate values to the above parameters the required task can be achieved. Example: Position the legend to the center Python3 # import the modules import plotly.express as px import pandas as pd # read the data data = pd.read_csv("bestsellers.csv") # scatter plot fig = px.scatter(data, x="Year", y="Price", color="Genre") fig.update_layout(legend=dict(y=0.5)) fig.show() Output: Example: Positioning legend on the plot Python3 # import the modules import plotly.express as px import pandas as pd # read the dataset data = pd.read_csv("bestsellers.csv") # scatter plot fig = px.scatter(data, x="Year", y="Price", color="Genre") # layout fig.update_layout(legend=dict(yanchor="top", y=0.9, xanchor="left", x=0.4)) fig.show() Output: Comment More infoAdvertise with us Next Article How to change the position of legend using Plotly Python? V vanshikagoyal43 Follow Improve Article Tags : Python Python-Plotly Practice Tags : python Similar Reads How to change the position of legend in Pygal? Prerequisites:  pygal Pygal is a Python module that is mainly used to build SVG (Scalar Vector Graphics) graphs and charts. Pygal is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. In this article, we will see how 2 min read How to position legends inside a plot in Plotly-Python? In this article, we will learn How to hide legend with Plotly Express and Plotly. A legend is an area describing the elements of the graph. In the plotly legend is used to Place a legend on the axes. Example 1: In this example, we are positioning legends inside a plot with the help of method fig.upd 2 min read How to create Tables using Plotly in Python? Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library 2 min read Change the legend position in Matplotlib In this article, we will learn how to Change the legend position in Matplotlib. Let's discuss some concepts :Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure w 2 min read How to Create Stacked area plot using Plotly in Python? Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library 2 min read Python - Change legend size in Plotly chart The data on the graph's Y-axis, also known as the graph series, is reflected in the legend of the graph. This is the information that comes from the columns of the relevant grid report, and it usually consists of metrics. A graph legend is usually displayed as a box on the right or left side of your 2 min read Python Plotly - How to customize legend? In plotly, we can customize the legend by changing order, changing orientation, we can either hide or show the legend and other modifications like increasing size, changing font and colour of the legend. In this article let's see the different ways in which we can customise the legend. To customize 3 min read How to hide legend with Plotly Express and Plotly in Python? In this article, we will learn How to hide legend with Plotly Express and Plotly. Here we will discuss two different methods for hiding legend in plotly and plotly express, using two different examples for each to make it more clear. Syntax: For legend: fig.update_traces(showlegend=False)fig.update( 2 min read Carpet Plots using Plotly in Python A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization libra 3 min read How to change figure size in Plotly in Python In this article, we will discuss how we can change the figure size in Plotly in Python. Let's firstly take about Plotly in Python. Plotly  Python library provides us with an interactive open-source Plotly library that can support over 40 unique chart types that cover a wide list of statistical, fin 4 min read Like