<tfoot id='7A13R'></tfoot>
    • <bdo id='7A13R'></bdo><ul id='7A13R'></ul>

        <legend id='7A13R'><style id='7A13R'><dir id='7A13R'><q id='7A13R'></q></dir></style></legend>
      1. <i id='7A13R'><tr id='7A13R'><dt id='7A13R'><q id='7A13R'><span id='7A13R'><b id='7A13R'><form id='7A13R'><ins id='7A13R'></ins><ul id='7A13R'></ul><sub id='7A13R'></sub></form><legend id='7A13R'></legend><bdo id='7A13R'><pre id='7A13R'><center id='7A13R'></center></pre></bdo></b><th id='7A13R'></th></span></q></dt></tr></i><div id='7A13R'><tfoot id='7A13R'></tfoot><dl id='7A13R'><fieldset id='7A13R'></fieldset></dl></div>
      2. <small id='7A13R'></small><noframes id='7A13R'>

        在 plotly 上绘制日期与时间的关系图

        时间:2023-09-28

        • <small id='IxpJk'></small><noframes id='IxpJk'>

          <i id='IxpJk'><tr id='IxpJk'><dt id='IxpJk'><q id='IxpJk'><span id='IxpJk'><b id='IxpJk'><form id='IxpJk'><ins id='IxpJk'></ins><ul id='IxpJk'></ul><sub id='IxpJk'></sub></form><legend id='IxpJk'></legend><bdo id='IxpJk'><pre id='IxpJk'><center id='IxpJk'></center></pre></bdo></b><th id='IxpJk'></th></span></q></dt></tr></i><div id='IxpJk'><tfoot id='IxpJk'></tfoot><dl id='IxpJk'><fieldset id='IxpJk'></fieldset></dl></div>

              • <bdo id='IxpJk'></bdo><ul id='IxpJk'></ul>

                  <tfoot id='IxpJk'></tfoot>
                    <tbody id='IxpJk'></tbody>
                  <legend id='IxpJk'><style id='IxpJk'><dir id='IxpJk'><q id='IxpJk'></q></dir></style></legend>
                  本文介绍了在 plotly 上绘制日期与时间的关系图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有几个数据集我想用日期作为 X 轴和时间作为 Y 轴来绘制.我在 Jupyter Notebook 工作.

                  from datetime 导入日期、时间从 plotly 离线导入为 py从 plotly.graph_objs 导入散点图,数据py.init_notebook_mode(连接=真)会议=分散(x=[日期(2017, 1, 1), 日期(2017, 1, 3), 日期(2017, 1, 3)],y=[时间(8, 0, 0), 时间(12, 0, 0), 时间(16, 0, 0)],text=['工作会议1', '工作会议1', '工作会议1'],模式='标记')锻炼=分散(x=[日期(2017, 1, 1), 日期(2017, 1, 2), 日期(2017, 1, 2)],y=[时间(7, 30, 0), 时间(14, 30, 0), 时间(17, 0, 0)],text=['锻炼 1', '锻炼 2', '锻炼 3'],模式='标记')数据 = 数据([会议、锻炼])py.iplot(数据)

                  我得到的结果是这样的:X 轴也包括时间,Y 轴按插入数据的顺序排列,而不是从下到上.我没有尝试修改范围/域来解决这个问题.从我在

                  绘图导入将日期时间导入为 dt会议 = plotly.graph_objs.Scatter(x=[dt.date(2017, 1, 1), dt.date(2017, 1, 3), dt.date(2017, 1, 3)],y=[dt.time(8, 0, 0), dt.time(12, 0, 0), dt.time(16, 0, 0)],text=['工作会议1', '工作会议1', '工作会议1'],模式='标记')锻炼 = plotly.graph_objs.Scatter(x=[dt.date(2017, 1, 1), dt.date(2017, 1, 2), dt.date(2017, 1, 2)],y=[dt.time(7, 30, 0), dt.time(14, 30, 0), dt.time(17, 0, 0)],text=['锻炼 1', '锻炼 2', '锻炼 3'],模式='标记')对于 [会议、锻炼] 中的 d:对于 i, t in enumerate(d.y):d.y[i] = dt.datetime.combine(dt.date(2017, 1, 1), t)布局 = plotly.graph_objs.Layout(yaxis={'类型':'日期','tickformat': '%H:%M'})fig = plotly.graph_objs.Figure(数据=plotly.graph_objs.Data([会议,锻炼]),布局=布局)plotly.offline.plot(图)

                  I have several data sets I would like to plot with dates as X axis and times as Y axis. I am working in Jupyter Notebook.

                  from datetime import date, time
                  from plotly import offline as py
                  from plotly.graph_objs import Scatter, Data
                  py.init_notebook_mode(connected=True)
                  
                  meetings = Scatter(
                      x=[date(2017, 1, 1), date(2017, 1, 3), date(2017, 1, 3)],
                      y=[time(8, 0, 0), time(12, 0, 0), time(16, 0, 0)],
                      text=['work meeting 1', 'work meeting 1', 'work meeting 1'],
                      mode='markers'
                  )
                  
                  workouts = Scatter(
                      x=[date(2017, 1, 1), date(2017, 1, 2), date(2017, 1, 2)],
                      y=[time(7, 30, 0), time(14, 30, 0), time(17, 0, 0)],
                      text=['workout 1', 'workout 2', 'workout 3'],
                      mode='markers'
                  )
                  
                  data = Data([meetings, workouts])
                  py.iplot(data)
                  

                  The result I get is this: The X axis includes time as well, and the Y axis goes in order of inserted data, not from bottom to top. Nothing I've tried with modifying the range/domain has fixed this. From what I've seen on the help page time objects aren't supported. Is there any way to make this type of plot work?

                  解决方案

                  In order to plot hours you would need to do two things:

                  • Set the yaxis type to date and the tickformat to %H:%M
                  • Convert your time objects to datetime objects

                  We just pretend everything on the yaxis happened on the same day but we only report the hour.

                  import plotly
                  import datetime as dt
                  
                  meetings = plotly.graph_objs.Scatter(
                      x=[dt.date(2017, 1, 1), dt.date(2017, 1, 3), dt.date(2017, 1, 3)],
                      y=[dt.time(8, 0, 0), dt.time(12, 0, 0), dt.time(16, 0, 0)],
                      text=['work meeting 1', 'work meeting 1', 'work meeting 1'],
                      mode='markers'
                  )
                  
                  workouts = plotly.graph_objs.Scatter(
                      x=[dt.date(2017, 1, 1), dt.date(2017, 1, 2), dt.date(2017, 1, 2)],
                      y=[dt.time(7, 30, 0), dt.time(14, 30, 0), dt.time(17, 0, 0)],
                      text=['workout 1', 'workout 2', 'workout 3'],
                      mode='markers'
                  )
                  
                  for d in [meetings, workouts]:
                      for i, t in enumerate(d.y):
                          d.y[i] = dt.datetime.combine(dt.date(2017, 1, 1), t)
                  
                  layout = plotly.graph_objs.Layout(yaxis={
                      'type': 'date',
                      'tickformat': '%H:%M'
                      }
                  )
                  
                  fig = plotly.graph_objs.Figure(
                      data=plotly.graph_objs.Data([meetings, workouts]),
                      layout=layout
                  )
                  plotly.offline.plot(fig)
                  

                  这篇关于在 plotly 上绘制日期与时间的关系图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Plotly 中的行悬停文本 下一篇:Plotly:如何使用 plotly 和 plotly express 绘制回归线?

                  相关文章

                1. <small id='xEo9Q'></small><noframes id='xEo9Q'>

                  <i id='xEo9Q'><tr id='xEo9Q'><dt id='xEo9Q'><q id='xEo9Q'><span id='xEo9Q'><b id='xEo9Q'><form id='xEo9Q'><ins id='xEo9Q'></ins><ul id='xEo9Q'></ul><sub id='xEo9Q'></sub></form><legend id='xEo9Q'></legend><bdo id='xEo9Q'><pre id='xEo9Q'><center id='xEo9Q'></center></pre></bdo></b><th id='xEo9Q'></th></span></q></dt></tr></i><div id='xEo9Q'><tfoot id='xEo9Q'></tfoot><dl id='xEo9Q'><fieldset id='xEo9Q'></fieldset></dl></div>

                      <legend id='xEo9Q'><style id='xEo9Q'><dir id='xEo9Q'><q id='xEo9Q'></q></dir></style></legend>

                      • <bdo id='xEo9Q'></bdo><ul id='xEo9Q'></ul>

                      <tfoot id='xEo9Q'></tfoot>