Hi,
I am trying to build something like this clock chart:
I played with Scatterpolar but ‘theta’ comes only with degrees.
Is there any way to use hour values?
Hi @Denis,
Here’s an approach to get you started. You’ll still need to specify the data points in degrees, but you can setup the tick labels to display hours
import plotly.graph_objs as go
def angle2hr(angle):
return (((angle - 15) % 360) + 15) / 15
def hr2angle(hr):
return (hr * 15) % 360
def hr_str(hr):
# Normalize hr to be between 1 and 12
hr_str = str(((hr-1) % 12) + 1)
suffix = ' AM' if (hr % 24) < 12 else ' PM'
return hr_str + suffix
data = [
go.Scatterpolar(
r = [0.5,1,2,2.5,3,4],
theta = [35,70,120,155,205,240],
mode = 'markers',
marker = dict(
color = 'peru'
)
)
]
layout = go.Layout(
showlegend = False,
)
layout.polar.angularaxis.direction = 'clockwise'
layout.polar.angularaxis.tickvals = [hr2angle(hr) for hr in range(24)]
layout.polar.angularaxis.ticktext = [hr_str(hr) for hr in range(24)]
fig = go.FigureWidget(data=data, layout=layout)
fig
Hope that helps!
-Jon
2 Likes
Hi @jmmease,
Thanks for your great workaround! It works!
1 Like