python - 如何在 Python 中使用 Bokeh 查看 Holoviews 的选项

标签 python python-3.x bokeh holoviews

一直在使用holoview来生成一些整洁的图。我想看看我对 hv.Curve 之类的东西有什么选择,当我使用 opts 时。几乎没有文档。 help page for holoview没有帮助。其中说“对于完整的文档以及可用的样式和绘图选项,请使用 hv.help(hv.Curve)。”然而,它没有解释如何使用它。我试过将它作为代码的一部分运行。我试过在我的终端中运行命令。我试过 print() ,并运行 help() .我只想知道我可以在这里放什么:overlay.opts(legend_position='right')此外legend_position ?这是我试图获取 hv.help(hv.Curve) 的代码命令工作。我知道这很可笑:

#!/usr/bin/env python3

import holoviews as hv
import numpy as np
import scipy.special
import pandas as pd
import bokeh
import pandas as pd
import numpy as np
import bokeh as bk
import plotly.graph_objects as go
import plotly.express as pex
import holoviews.plotting.bokeh
import numpy as np
import pandas as pd
from holoviews import *
from holoviews import Store
from bokeh.plotting import show
from holoviews import opts
from holoviews import Store
from holoviews import dim, opts

hv.help(hv.Curve)
这是我收到的错误消息:
        backend_registry = cls.store.registry.get(backend, {})
AttributeError: 'NoneType' object has no attribute 'registry'
感谢您的帮助,如果我能提供更多信息,请告诉我,因为这是我在本网站上的第一篇文章。

最佳答案

这里涉及到几个问题。首先,HoloViews 中的选项取决于您选择的绘图库后端,例如散景、matplotlib 或 plotly。在您的代码 list 中,您尚未加载绘图库后端,因此您将无法获得有关绘图选项(如 legend_position)的任何帮助。 .当然,您不应该收到像您看到的 AttributeError 这样的错误消息,因此请在 https://github.com/holoviz/holoviews/issues 提交问题。如果你能帮助我们复制那个虚假信息。我在运行 hv.help(hv.Curve) 时没有看到任何错误消息没有加载绘图后端;相反,我得到了 Sander 报告的内容,这是与绘图无关的选项的简短列表,无论后端如何,都应该始终可用:

$ python
>>> import holoviews as hv
>>> hv.help(hv.Curve)
Parameters of 'Curve'
=====================

Parameters changed from their default values are marked in red.
Soft bound values are marked in cyan.
C/V= Constant/Variable, RO/RW = ReadOnly/ReadWrite, AN=Allow None

Name                        Value                     Type     Bounds   Mode 

cdims                   OrderedDict()                 Dict              V RW 
datatype   ['dataframe', 'dictionary', 'grid', '...   List   (0, None)  V RW 
extents            (None, None, None, None)          Tuple              V RW 
group                      'Curve'                   String             C RW 
kdims                  [Dimension('x')]               List     (1, 2)   V RW 
label                         ''                     String             C RW 
vdims                  [Dimension('y')]               List   (1, None)  V RW 

Parameter docstrings:
=====================

cdims:    The constant dimensions defined as a dictionary of Dimension:value
          pairs providing additional dimension information about the object.
...          
vdims:    The value dimensions of the Chart, usually corresponding to a
          number of dependent variables.
如您所见,在这种情况下,这 7 个选项都没有帮助。如果您加载绘图后端,您将获得更多选项:
>>> hv.extension("bokeh")
>>> hv.help(hv.Curve)
Curve

Online example: http://holoviews.org/reference/elements/bokeh/Curve.html

-------------
Style Options
-------------

    alpha, color, hover_alpha, hover_color, hover_line_alpha, hover_line_color, line_alpha, line_cap, line_color, line_dash, line_join, line_width, muted, muted_alpha, muted_color, muted_line_alpha, muted_line_color, nonselection_alpha, nonselection_color, nonselection_line_alpha, nonselection_line_color, selection_alpha, selection_color, selection_line_alpha, selection_line_color, visible

(Consult bokeh's documentation for more information.)

------------
Plot Options
------------

The plot options are the parameters of the plotting class:

Parameters of 'CurvePlot'
=========================

Parameters changed from their default values are marked in red.
Soft bound values are marked in cyan.
C/V= Constant/Variable, RO/RW = ReadOnly/ReadWrite, AN=Allow None

Name                                 Value                         Type         Bounds     Mode  

active_tools                           []                          List       (0, None)    V RW  
... 57 other options...
zlim                               (nan, nan)                     Tuple                    V RW  

Parameter docstrings:
=====================

active_tools:      Allows specifying which tools are active by default. Note
                   that only one tool per gesture type can be active, e.g.
                   both 'pan' and 'box_zoom' are drag tools, so if both are
                   listed only the last one will be active.
... 57 other options...
zlim:              User-specified z-axis range limits for the plot, as a tuple (low,high).
                   If specified, takes precedence over data and dimension ranges.
这里的“样式”选项只列出,没有记录,因为它们是直接传递给底层绘图库的,因此不能在这里记录;在这种情况下,请参阅散景。其他选项有文档字符串,因为它们是由 HoloViews 实现的。
即便如此,如果您查看输出,您会注意到 legend_position实际上不在任何一个列表中。那是因为 legend_position是不属于 hv.Curve 的选项但来自 hv.Overlay ,用于可覆盖事物(曲线和许多其他对象)的通用容器。所以你需要做hv.help在 Overlay 类上:
>>> hv.help(hv.Overlay)
Overlay

Online example: http://holoviews.org/reference/containers/bokeh/Overlay.html

-------------
Style Options
-------------

    background_fill_alpha, background_fill_color, border_alpha, border_color, border_hover_alpha, border_hover_color, border_hover_line_alpha, border_hover_line_color, border_line_alpha, border_line_cap, border_line_color, border_line_dash, border_line_join, border_line_width, border_muted_alpha, border_muted_color, border_muted_line_alpha, border_muted_line_color, border_nonselection_alpha, border_nonselection_color, border_nonselection_line_alpha, border_nonselection_line_color, border_selection_alpha, border_selection_color, border_selection_line_alpha, border_selection_line_color, click_policy, glyph_height, glyph_width, label_height, label_standoff, label_width, legend_padding, legend_spacing, text_align, text_alpha, text_baseline, text_color, text_font, text_font_size, text_font_style

(Consult bokeh's documentation for more information.)

------------
Plot Options
------------

The plot options are the parameters of the plotting class:

Parameters of 'OverlayPlot'
===========================

Parameters changed from their default values are marked in red.
Soft bound values are marked in cyan.
C/V= Constant/Variable, RO/RW = ReadOnly/ReadWrite, AN=Allow None

Name                                 Value                         Type         Bounds     Mode  

active_tools                           []                          List       (0, None)    V RW  
...66 more options...
zlim                               (nan, nan)                     Tuple                    V RW  

Parameter docstrings:
=====================

active_tools:      Allows specifying which tools are active by default.
...
legend_position:   Allows selecting between a number of predefined legend position
                   options. The predefined options may be customized in the
                   legend_specs class attribute.
...
所以你可以看到 legend_position是一种选择,但毕竟,它仍然没有告诉你什么是允许的。令人沮丧!在许多情况下,您可以在 Jupyter 中键入它的一部分并调用制表符补全,但在这种情况下,使用字符串参数,最好的办法就是提供不正确的值。如果你在 Jupyter 中这样做,你会得到一个允许选项的列表:
>>> hv.Overlay().opts(hv.opts.Overlay(legend_position='aslkjf'))
ValueError: aslkjf not in Parameter legend_position's list of possible objects, valid options include [top_right, top_left, bottom_left, bottom_right, right, left, top, bottom]
信息很多,但很难找到!

关于python - 如何在 Python 中使用 Bokeh 查看 Holoviews 的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65191364/

相关文章:

python - 值错误 : array is too big when loading GoogleNews-vectors-negative

python - 切片查询集与切片 __in 子句中使用的列表相同吗?无法理解这种行为

django - Bokeh 模型不存在

bokeh - 如何将 Bokeh 可视化嵌入到谷歌幻灯片中?

python - 如何从 Bokeh 图中删除网格线?

python - Pymodm - Mongodb,如何在集合中创建索引

python - 无法使用 scrapy 从 Reddit 嵌入式提要窗口中获取 `href`

python-3.x - 我在 MNIST 上的逻辑回归中没有获得所需的准确度

python - django.core.exceptions.FieldError : Cannot resolve keyword 'timestamp' into field

python - 快速API: "ImportError: attempted relative import with no known parent package"