plotly / plotly/plotly.py

Problem with radialaxis ticks in polar plot when using date values

Offen
#3,481 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

Hello, I managed to create a polar heatmap plot following the examples given in #2024, but when trying to use time as the radial dimension I found some problems with the ticks. I tried with tickmodes auto, linear and array but got wrong ticks with all of them. The time values shown in the hover are correct, only the ticks appear to be wrong. Does anyone have a suggestion on what may be the problem?
Thank you.

import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.offline import plot

from datetime import datetime, timedelta

# dt_start, dt_end, dt_step ='2000-01-01', '2001-01-01', '1MS'
dt_start, dt_end, dt_step ='2000-01-01', '2000-01-10', '1D'

times = pd.date_range(dt_start, dt_end, freq=dt_step).values

dirs = np.arange(180, 271, 10)

r, theta = np.meshgrid(times, dirs)

z = np.random.random(r.shape)

hovertemplate = (f'date: %{{r|%Y-%m-%d %H:%M:%SZ}}<br>'
                 f'direction: %{{theta}}<br>'
                 f'value: %{{customdata[0]:.2f}}'
                 '<extra></extra>')

fig = go.Figure(go.Barpolar(r=r.ravel(),
                            theta=theta.ravel(),
                            marker_color=z.ravel(),
                            customdata=np.expand_dims(z.ravel(), 0).T,
                            hovertemplate=hovertemplate))

fig.update_layout(polar=dict(
    angularaxis=dict(tickvals=np.arange(0, 360, 45),
                     direction='clockwise'),
    radialaxis=dict(angle=45,
                    tickangle=45,
                    tickfont={'size': 14},
                    tickformat='%Y-%m-%d %H:%M:%S',

                    # tickmode='auto',
                    # nticks=5,

                    # tickmode='linear',
                    # tick0=times[0],
                    # dtick='1D',

                    tickmode='array',
                    tickvals=times,

                    )))

fig.show()

With tickmode='auto':

tickmode_auto

With tickmode='linear':

tickmode_linear

With tickmode='array':

tickmode_array

Using plotly.version = '5.4.0'

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 bereitgestellte Python-Beispiel mit Plotly 5.4.0 auszuführen, und vergleiche die von den Modi auto, linear und array erzeugten Ticks der radialen Achse. Verfolge die Verarbeitung der Ticks der radialen Achse für r-Daten mit Datumswerten. Erledigt ist die Aufgabe, wenn alle drei unterstützten Modi korrekt positionierte und formatierte Datums-Ticks erzeugen.

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
45/100

Neue Issues direkt in Ihr Postfach

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