plotly / plotly/plotly.py

Can not use transparency in px.imshow

Offen
#2,856 0 Kommentare 1 Reaktion 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 am using plotly 4.12.0.
The px.imshow function has this example in the docs:

import plotly.express as px
import numpy as np
img_rgb = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]],
                    [[0, 255, 0], [0, 0, 255], [255, 0, 0]]
                   ], dtype=np.uint8)
fig = px.imshow(img_rgb)
fig.show()

I have tried to add transparency to the plot with the following code:

import plotly.express as px
import numpy as np
img_rgb = np.array([[[255, 0, 0, .5], [0, 255, 0, .5], [0, 0, 255, .5]],
                    [[0, 255, 0, .5], [0, 0, 255, .5], [255, 0, 0, .5]]
                   ])
fig = px.imshow(img_rgb)
fig.show()

As suggested by the docs, passing a (M, N, 4), array would include transparency, but this resulted in an empty figure:
image

Using go.Image directly worked:

fig = go.Figure()
fig.add_traces(go.Image(z=img_rgb, colormodel='rgba'))

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

Reproduziere die leere Abbildung mit dem gemeldeten px.imshow-Beispiel unter Verwendung eines (M, N, 4)-Arrays und vergleiche sie anschließend mit dem funktionierenden go.Image-Beispiel unter Verwendung von colormodel='rgba'. Verfolge, wie px.imshow Eingaben von Bildern mit vier Kanälen verarbeitet; abgeschlossen ist die Untersuchung, wenn px.imshow das Bild wie dokumentiert mit Transparenz rendert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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