plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.97k stars 2.54k forks source link

showlegend=False not working in add_trace #2457

Closed Ripper1111 closed 2 months ago

Ripper1111 commented 4 years ago

Hi How to remove the legend on the back of the marker? Whenever I hover mouse over the market it gives trace0 legend even I used showlegend=False.

fig = go.Figure() fig.add_trace(go.Scatter( x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5], showlegend=False )) fig.add_trace(go.Scatter( x=[1, 2, 3, 4, 5], y=[5, 4, 3, 2, 1], )) fig.update_layout(showlegend=True) fig.show() legends

jdamiba commented 4 years ago

Hello @Ripper1111!

To achieve the behavior you are describing, you simply need to set the name attribute of your traces equal to an empty string, like this:

import plotly.express as px
import plotly.graph_objs as go
fig = go.Figure() 
fig.add_trace(go.Scatter( x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5], name="" )) 
fig.add_trace(go.Scatter( x=[1, 2, 3, 4, 5], y=[5, 4, 3, 2, 1], name="" )) 
fig.show()

Screen Shot 2020-05-11 at 5 19 08 PM

It is important to note that the showlegend attribute does not impact hover labels- it is used to toggle the visibility of legend in the top right of the figure.

To learn more about formatting hover labels, you can check out this documentation page: https://plotly.com/python/hover-text-and-formatting/

Hope that helps!

Ripper1111 commented 4 years ago

Thank You it solved the markers issue. But now I observed that when I applyed the code on candlestick chart the candlestick is also give the same legend at the label. Without add_traceit shows no trace0

# set the data from our data frame
data=[go.Candlestick(x=df_symbol_bar_Data['datetime'],
                open=df_symbol_bar_Data['open'],
                high=df_symbol_bar_Data['high'],
                low=df_symbol_bar_Data['low'],
                close=df_symbol_bar_Data['close'],
                showlegend=False)]

# display the Candlestic chart with the optional layout
figSignal = go.Figure(data=data,layout=layout)

figSignal.add_trace(go.Scatter(
    x=[high_time,low_time],
    y=[high_px,low_px],
    mode="markers+text",
    name="",
    text=["HIGH","LOW"],
    textposition=["top center","bottom center"],
    textfont=dict(
        family="sans serif",
        size=18,
        color=["LightSeaGreen","Red"]
    ),
    showlegend=False
))
figSignal.update_traces(showlegend=False)

addtrace

gvwilson commented 2 months ago

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson