plotly / plotly/plotly.py

Bar plot has bad additive color algebra when opacity<1

Offen
#4,416 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3
Vorherrschende Sprache
Python
Sterne
18.8k
Forks
2.8k
Ø Merge
16 Std. 26 Min.
Gemergte PRs (30 T.)
21

Beschreibung

I need to plot a few histograms and for aethetical reasons i prefer to make them semi-transparent and in overlay mode. I have a problem with how plotly handles color additions. I am aware that there is an additive color scheme and subtractive color scheme. I am not sure what scheme in used when plotly combines semi-transparent colors, but the result is absolutely unsatisfactory.
What i expected:
Given 2 original colors "#FD3216", "#00FE35". Mix them in 3'd color like in this site, then display it with given opacity. I expect it to be "#7e9825", but with opacity. Same for dark and light modes.
What i got:
In dark - "#37BD2B", in light "#4DD341". In dark mode the color is almost indestinguishable from one of parent colors, for almost any color sequence.

Here is the code to reproduce the issue:

import torch
from plotly import graph_objects as go, colors

clr_seq = iter(colors.qualitative.Light24)
N_bins = 20
distributions = {'A': torch.normal(0, 1, [1000]),
                 'B': torch.normal(1, 2, [1000]),}
fig = go.Figure()
for k, v in distributions.items():
    fig.add_bar(
        **dict(zip('yx', torch.histogram(
            v, N_bins, range=[-5, 5]))),
        name=k, marker_opacity=0.7, marker_color=next(clr_seq))
fig.update_layout(barmode='overlay', template='plotly_white')
fig.show()

image
image
image

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der bereitgestellten Python-Reproduktion unter Verwendung von go.Figure.add_bar, marker_opacity, barmode='overlay' und template='plotly_white'; vergleiche die gerenderten Überlappungsfarben im hellen und dunklen Modus. Verfolge das Verhalten der Opazitäts- und Farbkomposition von diesem Einstiegspunkt aus und betrachte das Issue als erledigt, wenn überlappende halbtransparente Balken in beiden Modi konsistent die dokumentiert erwartete Mischung erzeugen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python, pytorch
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.