我正在尝试创建一个图表,该图表将显示我打开计算机的时间的散点图。- 我正在离线使用。Y = 时间,X = 日期。
这很好用,但我不能让 Y 轴显示一天中的所有时间,而只能显示数据中的时间范围。
(例如,如果我每天只在 13:00-15:00 之间打开我的电脑,那么 Y 轴的范围只会从 13:00 到 15:00)
我试图通过使用布局中的“范围”属性在 Y 轴上显示一天中的所有时间,但它仍然对我不起作用。
我的代码示例:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
from plotly.graph_objs import *
from datetime import datetime, time
init_notebook_mode(connected=True)
# in the example i am using fabricated data. declaring the data:
time_data = [datetime(2017, 07, 28, 21, 37, 19), datetime(2017, 07, 29, 17, 11, 56), datetime(2017, 08, 01, 11, 15, 45), datetime(2017, 08, 02, 13, 54, 03)]
x_data = []
y_data = []
# creating the x-row data with dates only, and the y-row data with the time only
for row in time_data:
x_data.append(row.date())
y_data.append(datetime.combine(datetime(2017, 1, 1).date(), row.time))
#declaring the data for the graph
data = [Scatter(x=x_data, y=y_data, name='Times On', mode='markers')]
# creating the hour range
hours = []
for i in range (0, 24):
hours.append(datetime(2017, 1, 1, i, 0, 0))
# declaring the Layout with the 'range' attribute, and Figure
layout = dict(title='Times On', xaxis=dict(type='date'), yaxis={'type': 'date', 'tickformat': '%H:%M', 'range': hours})
fig = Figure(data=data, layout=layout)
# plotting
plot(figure_or_data=fig, filename='C:\Users\tototo\Desktop\Time-On')
有人知道有什么问题吗?任何帮助都会受到祝福!谢谢!