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

      <tfoot id='iD6Ix'></tfoot>

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

        <small id='iD6Ix'></small><noframes id='iD6Ix'>

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

        散景日期范围滑块

        Bokeh DateRangeSlider(散景日期范围滑块)

        1. <legend id='IkEk1'><style id='IkEk1'><dir id='IkEk1'><q id='IkEk1'></q></dir></style></legend>
          <tfoot id='IkEk1'></tfoot>

              <bdo id='IkEk1'></bdo><ul id='IkEk1'></ul>
            • <small id='IkEk1'></small><noframes id='IkEk1'>

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

                  <tbody id='IkEk1'></tbody>
                  本文介绍了散景日期范围滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近开始在 Bokeh 工作,完成了一些关于 datacamp 的快速课程,但我一直坚持创建 DateRangeSlider.滑块本身对我来说看起来不错,更改滑块上的值可以,但我无法更改绘图.

                  I have recently started working in Bokeh, finished some quick course on datacamp and I got stuck on creating a DateRangeSlider. Slider itself looks ok to me, changing the values on the slider works, but I can't make it to change the plot.

                  不确定我缺少什么,因为我找不到有关使用此特定工具的适当教程/信息,因此非常感谢您提供任何帮助.

                  Not sure what am I missing as I can't find proper tutorials / info on using this particular tool, so any help on that would be highly appreciated.

                  代码如下:

                  data['periodFrom'] = pd.to_datetime(data['periodFrom']).dt.date
                  data = data.rename(columns={'MWh/h' : 'MWH'})
                  source = ColumnDataSource(data={
                      'x'       : data.periodFrom,
                      'y'       : data.MWH,
                      'point'      : data.pointLabel,
                      'direction'      : data.directionKey
                  })
                  xmin, xmax = min(data.periodFrom), max(data.periodFrom)
                  ymin, ymax = min(data['MWH']), max(data['MWH'])
                  
                  plot = figure(title='Gas renomination', plot_height=400, plot_width=700,
                                x_range=(xmin, xmax), y_range=(ymin, ymax))
                  
                  plot.line(x='x', y='y', source=source)
                  
                  plot.xaxis.axis_label ='Date'
                  plot.yaxis.axis_label = 'MWh/h'
                  
                  def update_plot(attr, old, new):
                      yr = slider.value
                      new_data = {
                      'x'       : data.loc[yr[0]:yr[1]].periodFrom,
                      'y'       : data.loc[yr[0]:yr[1]].MWH,
                      'point'      : data.loc[yr[0]:yr[1]].pointLabel,
                      'direction'      : data.loc[yr[0]:yr[1]].directionKey
                      }
                      source.data = new_data
                  
                  slider = DateRangeSlider(start=date(2016,1,1), end=date.today(), step=1, 
                           value=(date(2016,1,1),date(2016,2,1)), title='Date', width=1000)
                  
                  slider.on_change('value', update_plot)
                  
                  curdoc().add_root(plot)
                  curdoc().add_root(slider)
                  show(plot)
                  

                  这是我每次更改滑块值时在命令提示符中收到的错误消息:

                  And here's the error message I get in the commmand prompt every time I change slider's value:

                  2018-07-19 11:56:55,387 error handling message Message 'PATCH-DOC' (revision 1): KeyError(1451606400000,)
                  

                  最好,皮奥特雷克

                  我在滑块上做了一些工作,现在没有出现任何错误,但是当我向任何方向移动滑块时,情节就会消失.单独过滤效果很好(即当我将 'data[data.index > yr[0]].periodFrom' 放在控制台中时),但使用新值更新绘图似乎有问题.

                  I did some work on the slider, now not raising any errors, but the plot vanishes when I move the slider in any direction. Individually filtering works well (i.e. when I put 'data[data.index > yr[0]].periodFrom' in the console), but it seems like there's something wrong with updating the plot with new values.

                  data['periodFrom'] = pd.to_datetime(data['periodFrom'])
                  data.index = data['periodFrom'].astype(np.int64) // 10 ** 9
                  data.index = data.index.astype(np.float)
                  
                  data = data.rename(columns={'MWh/h' : 'MWH'})
                  source = ColumnDataSource(data={
                      'x'       : data.periodFrom,
                      'y'       : data.MWH,
                      'point'      : data.pointLabel,
                      'direction'      : data.directionKey
                  })
                  
                  xmin, xmax = min(data.periodFrom), max(data.periodFrom)
                  ymin, ymax = min(data['MWH']), max(data['MWH'])
                  
                  # Create the figure: plot
                  plot = figure(title='Gas renomination', plot_height=400, plot_width=700,
                                x_range=(xmin, xmax), y_range=(ymin, ymax))
                  
                  plot.line(x='x', y='y', source=source)
                  
                  plot.xaxis.axis_label ='Date'
                  plot.yaxis.axis_label = 'MWh/h'
                  
                  #slider
                  def update_plot(attr, old, new):
                      yr = slider.value
                      yr=list(yr)
                      [float(i) for i in yr]
                      new_data = {
                          'x' : data[(data.index > yr[0]) & (data.index < yr[1])].periodFrom,
                          'y' : data[(data.index > yr[0]) & (data.index < yr[1])].MWH,
                          'point' : data[(data.index > yr[0]) & (data.index < yr[1])].pointLabel,
                          'direction' : data[(data.index > yr[0]) & (data.index < yr[1])].directionKey}
                  
                  print(new_data)
                  source.data = new_data
                  
                  slider = DateRangeSlider(start=datetime(2016,1,2).timestamp(), 
                  end=datetime.today().timestamp(), step=1, value= 
                  (datetime(2016,2,2).timestamp(),datetime(2016,3,3).timestamp()), title='Date', 
                  width=1000)
                  slider.on_change('value', update_plot)
                  
                  #dropdown
                  
                  def update_dropdown(attr, old, new):
                      point_select = select.value
                      data_selected ={
                          'x' : data[data['pointLabel'] == point_select].periodFrom,
                          'y' : data[data['pointLabel'] == point_select].MWH,
                          'point' : data[data['pointLabel'] == point_select].pointLabel,
                          'direction' : data[data['pointLabel'] == point_select].directionKey}
                  
                      source.data=data_selected
                  
                  select = Select(title="Point", options=pointlabels, value='Kondratki')
                  select.on_change('value', update_dropdown)
                  
                  curdoc().add_root(select)
                  curdoc().add_root(plot)
                  curdoc().add_root(slider)
                  

                  我的原始数据框是 40639 x 6,打印 new_data 后我得到一个字典:

                  My original dataframe is 40639 x 6, after printing new_data i get a dict:

                  我还在代码的第二部分添加了一个 Select 小部件,data_selected 的格式与 DateRangeSlider 中的格式相同(参见:图片).对我来说奇怪的是 Select 可以完美运行,而 DataRangeSlider 每次单击时都会使情节消失.

                  I also added a Select widget in the second part of the code, data_selected is the same format as in DateRangeSlider (see: image). What's strange for me is that Select works perfectly, while DataRangeSlider makes the plot vanish every time I click it.

                  推荐答案

                  虽然为方便起见可以使用 datetime 对象初始化滑块,但滑块值实际上表示为浮点时间戳,具体来说,是自 epoch 以来的毫秒数.这意味着您尝试直接使用该值索引您的数据框大致相当于:

                  Although sliders can be initialized with datetime objects for convenience, the slider value is actually represented as a floating point timestamp, specificically, the number of milliseconds since epoch. That means your attempts to index your dataframe directly with the value are roughly equivalent to:

                  data.loc[1451606400000].periodFrom
                  

                  由于显而易见的原因,这不起作用.

                  Which does not work for obvious reasons.

                  根据名称 yr,您似乎想用年份值索引您的数据框?然后您需要将时间戳值转换为真实的日期时间和额外的年份:

                  Based on the name yr, it looks like you want to index your dataframe with values that are years? Then you need to convert the timestamp value to a real datetime and extra the year:

                  In [6]: from datetime import datetime
                  
                  In [7]: datetime.fromtimestamp(1451606400000/1000).year
                  Out[7]: 2015
                  

                  顺便说一句,没有理由在 Bokeh 服务器应用程序中使用或调用 show.

                  As an aside, there is never a reason to use or call show in a Bokeh server application.

                  这篇关于散景日期范围滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  <tfoot id='hFDYy'></tfoot>

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

                    <small id='hFDYy'></small><noframes id='hFDYy'>

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