【问题标题】:Unable to set bokeh plotting parameters using BOKEH + HOLOVIEW plotting option via Python无法通过 Python 使用 BOKEH + HOLOVIEW 绘图选项设置散景绘图参数
【发布时间】:2016-08-19 06:16:59
【问题描述】:

是否有任何文档指定如何通过 holoview 传递 Bokeh 参数? 我正在阅读教程,但我认为我错过了一些小东西。 网上有一个例子在 Ipython 中描述了这一点,但我试图通过没有 Ipython 笔记本的 python 来做。 http://holoviews.org/Tutorials/Bokeh_Backend.html?highlight=bokeh

当我运行这个程序时,我得到了曲线,但颜色没有改变,我也得到这个错误:WARNING:root:Curve01537: Setting non-parameter attribute style={'line_color': 'green'} using a mechanism仅用于参数

如何设置参数?

    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()

【问题讨论】:

    标签: plot backend bokeh curve holoviews


    【解决方案1】:

    在 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)
    

    Options Tutorial 描述了如何设置这样的选项,但如果您发现其中一些不清楚的地方,请告诉我们。

    【讨论】:

      【解决方案2】:

      这个语法也可以

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

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

      除了 Philipp 的链接之外,还可以在 here 找到有关设置选项的详细信息。

      【讨论】:

        猜你喜欢
        • 2017-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多