Reputation: 413
I've created a surface plot to visualise a variable by hour of day and day of week. The plot works, however, I'm unable to change the default tick text (0,1,2,3...) to "Monday" "Tuesday" etc.
data = [go.Surface(z=df.values.tolist(), colorscale='Blackbody')]
layout = go.Layout(
xaxis=dict(
tickmode = 'Array',
ticktext = Hours, #'Hours' is a list with 24 str elements e.g. "00:00"
tickvals = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]
),
yaxis=dict(
tickmode = 'Array',
ticktext = Weekdays, ##'Weekdays' is a list with 7 str elements e.g. "Monday"
tickvals = [0,1,2,3,4,5,6]
)
)
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename='test.html')
Expected - X axis tick marks: ("00:00", "00:01", ...), Y axis tick marks: ("Monday", "Tuesday", ...).
Actual - X marks: (0, 1, 2, ... 23), Y marks: (0, 1, 2, ... 6)
My DataFrame is a simple day/time matrix with 24 columns (hour) and 7 rows (weekday)
df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 7 entries, Monday to Sunday
Data columns (total 24 columns):
00:00 7 non-null float64
01:00 7 non-null float64
02:00 7 non-null float64
---------------------------
21:00 7 non-null float64
22:00 7 non-null float64
23:00 7 non-null float64
dtypes: float64(24)
memory usage: 1.4+ KB
Upvotes: 0
Views: 845
Reputation: 413
I was missing an outer dictionary containing xaxis and yaxis, solution below:
data = [go.Surface(z=df.values.tolist(), colorscale='Blackbody')]
layout = go.Layout(
scene=dict(
xaxis=dict(
tickmode = "Array",
ticktext = Hours,
tickvals = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]
),
yaxis=dict(
tickmode = "Array",
ticktext = Weekdays,
tickvals = [0,1,2,3,4,5,6]
)
)
)
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename='test.html')
Upvotes: 1