Skip to content

Feature Request: Plotly Express ability to change the icon in the legend #4342

@e-wallace

Description

@e-wallace

Unfortunately this is not possible via plotly currently. Plotly's legend symbols are 1-1 with their marker counterparts such that the user can essentially only change the legend via the markers characteristics. I.e. Making the bar graph purple will make the legend symbol purple, but you can't directly change the legend to purple without changing the bar graph to be purple. source

When creating a bar graph like so:

import plotly.express as px
df = px.data.tips()
fig = px.histogram(df, x="sex", y="total_bill",
             color='smoker', barmode='group',
             height=400)
fig.show()

It creates a legend that reflects the graph style.
Screen Shot 2023-08-28 at 4 59 45 PM

There's no property that allows you to change or customize the icon used in the legend.

The request is to create a property in plotly express that allows you to choose the legend marker. Default could be the current case, which is to match the graph. Other options could be line, square or circle.

This FR came from an enterprise client and in my research I found it was echoed by the community as well
https://stackoverflow.com/questions/66814448/plotly-how-to-change-legend-item-shape-from-line-to-box-or-circle-in-a-line-cha
https://stackoverflow.com/questions/66456467/custom-markers-in-plotly-dash-legend

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions