我创建了一个表面图,用于按小时和星期几来显示变量。该情节有效,但我无法将默认刻度文本(0,1,2,3 ...)更改为"星期一" "星期二"等
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')
预期 - X轴刻度线:(" 00:00"," 00:01",...),Y轴刻度线:("星期一&# 34;,"星期二",......)。
实际 - X标记:(0,1,2,... 23),Y标记:(0,1,2,... 6)
我的DataFrame是一个简单的日/时矩阵,有24列(小时)和7行(工作日)
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
答案 0 :(得分:0)
我错过了一个包含xaxis和yaxis的外部字典,解决方案如下:
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')