plotly / plotly/plotly.py

enable assignment of "Download plot as a png" value to variable

Offen
#2,889 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Bug (or Feature Request?):

I want to get the annotated image after I used drawrect. The only possible way, for now, is using the Download plot as a png button, save it on pc, read it. Is there a straightforward way to do that?

I mark it as a bug (or maybe it's the intended behavior by the developer) because fig.to_image(format="png", engine="kaleido") return the original image, not the annotated one.

Note: I'm using a jupyter notebook

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
config = dict({    
    'modeBarButtonsToAdd':[
        'drawrect',
        'eraseshape',
    ],
    'modeBarButtonsToRemove':[
        'toggleSpikelines','hoverCompareCartesian'
    ]
})
fig.show(config=config)

original)

do some annotations...

annotated

then run:

import numpy as np
import cv2
import matplotlib.pyplot as plt
annotate_image = fig.to_image(format="png", engine="kaleido")
nparr = np.frombuffer(annotate_image, np.uint8)
img_numpy = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
plt.imshow(img_numpy[...,::-1])

saved_image

The plt.imshow(img_numpy[...,::-1]) will show the original image, not the annotated image. How to use fig.to_image(format="png", engine="kaleido") to include the annotation of drawrect? Or any workaourd?

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 dem Einstiegspunkt fig.show(config=config) und der drawrect-Interaktion und vergleiche sie anschließend mit fig.to_image(format="png", engine="kaleido"). Ermittle, ob der annotierte Zustand über den bestehenden Exportpfad weitergegeben werden kann; als abgeschlossen gilt die Aufgabe, wenn das resultierende zugewiesene Bild das gezeichnete Rechteck enthält. Im Issue werden keine Repository-Dateien oder Tests genannt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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