简体   繁体   English

绘图/短划线日期时间图

[英]Plotly/Dash datetime plot

How does plotly works with datetime ? 如何与datetime配合使用? Can't I plot datetime x datetime objects in plotly? 我不能以绘图方式绘制datetime x datetime对象吗? This question is due to some problems when plotting "hours / minutes" in the y axis, it goes messy. 这个问题是由于在y轴上绘制“小时/分钟”时出现的一些问题而引起的。

数据

In the example my hours plot starts at 11:13 and ends at 10:54, but the range is 08:33 to 11:55 在示例中,我的小时数图开始于11:13,结束于10:54,但范围是08:33至11:55

When plotting in matplotlib, it recognizes the range ( what I want) but in dash it creates a ladder from the lowest values to the highest values 在matplotlib中绘制时,它可以识别范围(我想要的),但在破折号中,它会创建从最低值到最高值的阶梯

Yes, I've already tried to 'yaxis':{tickformat:'%HH:%MM:%SS' 是的,我已经尝试过'yaxis':{tickformat:'%HH:%MM:%SS'

You can convert columns to appropriate type and then plot it using plotly. 您可以将列转换为适当的类型,然后使用plotly对其进行绘制。 Here are useful page to doing this: ref . 这是执行此操作的有用页面: ref Code: 码:

# import necessaries libraries
import plotly.offline as py
import plotly.graph_objs as go
import pandas as pd
from datetime import datetime

# Create data
df = pd.DataFrame({"date": ['01/08/2018', '02/08/2018', '06/08/2018',
                            '10/08/2018', '12/08/2018', '13/08/2018',
                            '15/08/2018'],
                   "time": ['06:40:00', '05:57:00', '02:56:00', '03:57:00',
                            '12:24:00', '10:48:00', '15:56:00']})
# For now, columns data are not recognized
print(df.dtypes)
# Convert columns to datetime and plotly should recognize it
df['date'] = pd.to_datetime(df['date'], format='%d/%m/%Y')
df['time'] = pd.to_datetime(df['time'], format='%H:%M:%S')
# You see, that type of columns changed
print(df.dtypes)
# Build a plot
data = [go.Scatter(x=df.time, y=df.date)]
# Plot a plot
py.plot(data, filename='time-series-simple.html', auto_open=False)

Output: 输出: 图形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM