Plotly – How to show legend in single-trace scatterplot with plotly express?
In this article let’s see how to show legend in single-trace scatterplot with plotly express. A ‘trace’ is the name given to each plot inside the chart. Generally in plotly legend is not visible for single trace scatter plots.
In the below, example packages and data are imported and a single trace scatter plot is plotted using px.scatter(). fig.layout.showlegend= True doesn’t work in this case so we need to enable showlegend by using this code fig[‘data’][‘showlegend’]=True. fig[‘data’][‘name’]=’Humidity’ says that name of the only variable in the legend is ‘Humidity’.
To view and download the CSV file used click here.
Before setting legend
After setting legend.
My Personal Notes arrow_drop_up
Please Login to comment...