How do I remove this star from the legend?

I want to remove this little star that comes by default in the Plotly legend (4.9.0), I didn’t see an option in the documentation that would do that.

image

I have never seen this star! Can you tell us about the environment you’re seeing it in? Cc @alexcjohnson @archmoj :slight_smile:

Does anyone see this star in our docs at https://plotly.com/python ?

1 Like

This is example of my code:

import plotly.express as px
from kaleido.scopes.plotly import PlotlyScope
import plotly.graph_objects as go
import pathlib

GREEN_01 = '#02B8AB'
BLACK = '#374649'
def multibar(values, labels):
    scope = PlotlyScope()
    data = list()
    colors = [GREEN_01, BLACK]
    for idx, (key, value) in enumerate(values.items()):
        data.append(go.Bar(
                name=key, 
                x=labels, 
                y=value,
                texttemplate=value,
                marker_color=colors[idx]
            )
        )
    fig = go.Figure(data=data)
    fig.update_layout(
        uniformtext_minsize=9,
        plot_bgcolor='rgb(250,250,250)',
        yaxis_visible=False, 
        yaxis_showticklabels=False,
        xaxis_tickfont_size=9,
        xaxis_tickangle=-45,
        barmode='group',
        legend=dict(
            orientation="h",
            yanchor="bottom",
            y=1.02,
            xanchor="right",
            x=1,
            bgcolor="White",
            bordercolor="White",
        )
    )
    fig.update_traces(
        textposition='outside',
        textfont_size=9,
        showlegend=True
    )
    with open(f"{str(pathlib.Path().absolute())}/test.svg", "wb") as f:
        f.write(scope.transform(fig, format="svg"))

I used Grouped Bar Chart (https://plotly.com/python/bar-charts/) and i did some adjust.
Note: I don’t tested this code part outside of my project.

Note: This code part dont show a star, but in my project which use other libs and more complex show this star, i don’t understand.

I suspect there is some CSS in the surrounding system where you are displaying this image which is causing some strange rendering artifacts… Without a fuller description of the context here it will be difficult to help you, as this seems very localized :slight_smile:

I am using the Python version of the library, so there would be no css in this case, I realized that in all graphics that I have a caption this problem has. With showlegend=False I remove everything, even the star, so I suspect it is not something external.

This star shows up on SVG export? If you could provide some code which reproduces this reliably, we can fix it, but it’s definitely a bug and not a feature, so there no way to “turn the star off” :slight_smile:

1 Like

I understand, I will try to find out what can be in the project, when there is some positive feedback I post here. Thanks for the support.

Hi @nicolaskruchten, i believe the problem is with the svg2rlg library and not with Plotly, I did a little test, follow the small script and the results:

import os
import pathlib
from reportlab.graphics import renderPDF
from svglib.svglib import svg2rlg
from kaleido.scopes.plotly import PlotlyScope
import plotly.graph_objects as go


def pie():
    scope = PlotlyScope()
    labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
    values = [4500, 2500, 1053, 500]
    fig = go.Figure(data=[go.Pie(labels=labels, values=values)])

    with open(f"{str(pathlib.Path().absolute())}/test.svg", "wb") as f:
        f.write(scope.transform(fig, format="svg"))

    image = os.path.join(str(pathlib.Path().absolute()), 'test.svg')
    renderPDF.drawToFile(svg2rlg(image), "file.pdf")


if __name__ == "__main__":
    pie()

Plotly Result:

Result using the svg2rlg library to convert SVG to ReportLab:

I hope this helps other people, if they encounter the same problem.

OK cool, thanks for sharing! I kinda like the star though, we should make that an optional thing to turn on :wink: :star2:

1 Like

Problem resolved: https://github.com/deeplook/svglib/issues/250

Plotly + svglib + reportLab = OK! :+1: