plotly / plotly/plotly.py

annotation coordinates do not respect log scaling

Offen
#2,580 11 Kommentare 2 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

When adding annotations to a plot that uses log scaling, the annotation coordinates need to be rescaled to represent the log10 of the actual coordinates. While this is documented behavior, it is rather counterintuitive and should be fixed.
Seemingly no other axis-types (date, for instance) needs special treatment but works without modifying the underlying data.

Minimum example demonstrating the point, i.e. label_y is 4 but plotted at 10^4:

df = pd.DataFrame(data={'x':[1,2,3,4],
                        'y':[1,4,9,16],
                        })

fig = px.line(df,
              x='x',
              y='y',
              log_y=True,
              log_x=True,
              )

annotations = []
fig.for_each_trace(
    lambda trace: annotations.append(dict(x=np.log10(np.sqrt(trace.x[0]*trace.x[-1])),
                                          y=np.sqrt(trace.y[0]*trace.y[-1]),
                                          text=f'({np.sqrt(trace.x[0]*trace.x[-1])},{np.sqrt(trace.y[0]*trace.y[-1])})',))
)

fig.update_layout(annotations=annotations,
                  width=300,
                  height=300,
                  )
fig.show()

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

Keine Quelldatei oder kein Test wird genannt. Beginne damit, das minimale Beispiel mit logarithmisch skalierten x- und y-Achsen zu reproduzieren, und verfolge dann, wie Anmerkungen und Achsenkoordinaten behandelt werden; fertig ist es, wenn Anmerkungen tatsächliche Datenkoordinaten auf logarithmischen Achsen akzeptieren, während Datums- und andere Achsentypen weiterhin funktionieren, ohne die zugrunde liegenden Daten zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
plotly, python
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.