Mootmoot
Mootmoot

Reputation: 21

How to remove 'Aa' from the legend in Plotly.py?

How to remove 'Aa' from the legend?

The code below is from the example on this page under Adding Text to Data in Line and Scatter Plots: https://plotly.com/python/text-and-annotations/

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(
    x=[0, 1, 2],
    y=[1, 1, 1],
    mode="lines+markers+text",
    name="Lines, Markers and Text",
    text=["Text A", "Text B", "Text C"],
    textposition="top center"
))

fig.add_trace(go.Scatter(
    x=[0, 1, 2],
    y=[2, 2, 2],
    mode="markers+text",
    name="Markers and Text",
    text=["Text D", "Text E", "Text F"],
    textposition="bottom center"
))

fig.add_trace(go.Scatter(
    x=[0, 1, 2],
    y=[3, 3, 3],
    mode="lines+text",
    name="Lines and Text",
    text=["Text G", "Text H", "Text I"],
    textposition="bottom center"
))

fig.show()

Edit: I would like to keep the text in the markers.

Thanks

Upvotes: 1

Views: 1460

Answers (2)

akhiljoseph
akhiljoseph

Reputation: 1

You can add the current latest plotly cdn

<script src="https://cdn.plot.ly/plotly-2.8.3.min.js"></script>

'Aa' will disappear

Upvotes: 0

Roy2012
Roy2012

Reputation: 12493

Advanced Solution

The advanced solution is to customize the CSS before calling fig.show():

from IPython.core.display import HTML
HTML("""
<style>
g.pointtext {display: none;}
</style>
""")

fig.show()

This results in the desired behavior.

Simple solution

The 'Aa' is the result of the existence of text in the markers. If you remove text and leave just markers and lines, the 'Aa' disappears.

For example:

fig.add_trace(go.Scatter(
    x=[0, 1, 2],
    y=[1, 1, 1],

    # mode="lines+markers+text",  # comment out
    mode="lines+markers",         # new code 

    name="Lines, Markers and Text",
    text=["Text A", "Text B", "Text C"],
    textposition="top center"
))

Upvotes: 3

Related Questions