plotly / plotly/plotly.py

Static image excludes layout_images if source is not absolute path

Offen
#4,548 0 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

Hi there, I am currently failing to export a static image including a layout image.
The export does not show any errors but the layout images are just omitted in the exported data.
This is the case for fig.write_image() as well as plotly.io.to_image().
A simple example is:

import plotly.graph_objects as go
import numpy as np

x = np.linspace(0,3*np.pi,1000)
y = np.sin(x)

plotly_logo="Images/plotly.png"
fig = go.Figure(go.Scatter(x=x,y=y))
fig.add_layout_image(dict(
    source=plotly_logo,
    xref="paper",
    yref="paper",
    x=.5,
    y=.5,
    xanchor="center",
    yanchor="middle",
    sizex=.4,
    sizey=.4
))
fig.write_image("Images/test.png", scale=3)

The image will be saved and show the sine curve but the plotly logo will not be visible.
But fig.show() shows the plotly logo nicely centered in the graph.

Switching out the relative path Images/plotly.png with a absolute one e.g. /home/user/Images/plotly.png the logo appears in the exported image file as well.
For me it seems, that the source argument is interpreted differently for different methods of showing the image.
Maybe someone knows, where to look to fix this?

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 damit, das Beispiel mit einer relativen layout-image-Quelle zu reproduzieren, und vergleiche dabei fig.write_image() und plotly.io.to_image() mit dem Fall eines absoluten Pfads. Erledigt ist die Aufgabe, wenn das layout-image mit relativem Pfad in statischen Exporten beider Methoden ohne Fehler erscheint.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
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
35/100

Neue Issues direkt in Ihr Postfach

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