close

How to hide legend with Plotly Express and Plotly

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to hide legend with Plotly Express and Plotly in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to hide legend with Plotly Express and Plotly?

  1. How to hide legend with Plotly Express and Plotly?

    For Advanced users: You can also enable/disable the legend for individual traces in a figure by setting the showlegend property of each trace. For instance:

  2. hide legend with Plotly Express and Plotly

    For Advanced users: You can also enable/disable the legend for individual traces in a figure by setting the showlegend property of each trace. For instance:

Method 1

try this:

my_data = [go.Bar( x = df.Publisher, y = df.Views)]
my_layout = go.Layout({"title": "Views by publisher",
                       "yaxis": {"title":"Views"},
                       "xaxis": {"title":"Publisher"},
                       "showlegend": False})

fig = go.Figure(data = my_data, layout = my_layout)

py.iplot(fig)
  • the argument showlegend is part of layout object which you did not specify in your code
  • The code may also work if you do not wrap the layout object my_layout inside a go.Layout(). It could work by simply keeping my_layout a dictionary
  • as for plotly.express, try fig.update_layout(showlegend=False). All the arguments are the same. Accessing them varies slightly.

Method 2

After creating the figure in plotly, to disable the legend you can make use of this command:

fig.update_layout(showlegend=False)

For Advanced users: You can also enable/disable the legend for individual traces in a figure by setting the showlegend property of each trace. For instance:

fig.add_trace(go.Scatter(
    x=[1, 2],
    y=[1, 2],
    showlegend=False))

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read