无法使用Python通过BOKEH + HOLOVIEW绘图选项设置bokeh绘图参数

3
有没有关于如何通过holoview传递Bokeh参数的文档?我正在阅读教程,但我觉得可能有些小细节我漏掉了。在线上有一个IPython的例子描述了这个问题,但我想在不使用IPython notebook的情况下实现它。 http://holoviews.org/Tutorials/Bokeh_Backend.html?highlight=bokeh 当我运行这个程序时,曲线出现了,但是颜色没有改变,我还得到了这个错误: WARNING:root:Curve01537: Setting non-parameter attribute style={'line_color': 'green'} using a mechanism intended only for parameters
我们如何设置参数呢?
    Code Example here
    from pprint import pprint, pformat
    import holoviews as hv
    import numpy as np
    import pathlib, os
    import webbrowser
    import lasio, las
    from holoviews import Store
    from holoviews.plotting.bokeh.element import (line_properties, fill_properties, text_properties)

   def plot_bokeh(plot):

       #Create renderer instance
       myrenderer = hv.Store.renderers['bokeh'].instance(fig='html')
       out_file_name = "".join(["./OUTPUT/","gyro", "_graph.html"])
       with open (out_file_name, 'w') as f:
       #Plot static html
           f.write (myrenderer.static_html(plot))
       f.close()
                     webbrowser.open_new_tab(pathlib.Path(os.path.abspath(out_file_name)).as_uri())


    def holoview_sandbox():


      curve_opts = dict(line_color='green')
      xs = np.linspace(0, np.pi*4, 100)
      data = (xs, np.sin(xs))


      holo_plot = hv.Curve(data, label='MY LABEL' , style=curve_opts) 
      plot_bokeh(holo_plot)

    if __name__ == '__main__':
        holoview_sandbox()
2个回答

2
在HoloViews中,选项并不绑定到对象本身,这有各种好处,包括能够使用不同的后端进行绘图。设置样式选项的纯Python方法如下:
  curve_opts = dict(line_color='green')
  xs = np.linspace(0, np.pi*4, 100)
  data = (xs, np.sin(xs))
  holo_plot = hv.Curve(data, label='MY LABEL')(style=curve_opts)

选项教程介绍了如何设置类似这样的选项,但如果您发现其中有些不清楚的地方,请告诉我们。


0

这种语法也可以工作

holo_plot.opts(style={'color': 'green'})

当你在 Philipp 的答案的 dict() 中将条目 'line_color' 更改为 'color' 时,这也适用于 matplotlib 后端。

关于设置选项的详细信息,除了 Philipp 的链接 这里 也可以找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接