plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
17.09k stars 1.87k forks source link

Add an option to set the opacity of markers in the legend #7208

Open subwaymatch opened 1 month ago

subwaymatch commented 1 month ago

Can you kindly consider adding an option to set the opacity of legend markers? Currently, the opacities of the legend's markers are tied to the opacity values of the traces.

Plotly Version plotly.js v2.35.2

Some scatter plots use a very low opacity (<0.10) to display the concentration of overlapping data points.

👇 This can result in imperceptible marker colors in the legend, as shown below:

👇 Feature request: add an option to set the legend marker opacity

I used a workaround to manually set the opacity of the scatterpts class using CSS.

/* current workaround */
.legendpoints .scatterpts {
  opacity: 1 !important;
}

👇 CodePen for Testing

image

Related posts:

Thank you for maintaining one of the best DataViz libraries! 👍

Lexachoc commented 1 month ago

I quickly made a support based on your request.

In below, the legend marker's opacity will not using the opacity value from marker.opacity (defined in data) but from legend.opacity (defined in layout)

layout = {
    legend: {
        opacity: 1
    }
}

image

but I wonder if we need to be more specific, e.g., put the opacity option inside the marker (or other name)

layout = {
    legend: {
        marker: {
            opacity: 1
        }
    }
}

Or should it not be within layout, but be inside data for each individual trace (But I guess that would be more complex)?

I need more thoughts/advice from more people (especially the Plotly team) so I can further implement it as there are other types of charts that will use the legend. Currently I'm only focusing on scatter plots and bar charts (and histograms).