我需要在箱线图中添加一条水平线。通过holoviews
手册进行了查看,似乎应该在这种情况下使用HLine
。不幸的是我得到一个错误:
ValueError: all the input arrays must have same number of dimensions
示例:
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
groups = [chr(65+g) for g in np.random.randint(0, 3, 200)]
boxwhisker = hv.BoxWhisker(
(groups, np.random.randint(0, 5, 200), np.random.randn(200)),
['Group', 'Category'],
'Value'
).sort() * hv.HLine(1)
boxwhisker.opts(
opts.BoxWhisker(
box_color='white',
height=400,
show_legend=False,
whisker_color='gray',
width=600
),
opts.HLine(color='green', line_width=2)
)
layout = hv.Layout(boxwhisker)
hv.save(layout, 'boxplot.html')
跟踪:
File "/home/python3.6/site-packages/holoviews/plotting/renderer.py", line 545, in save
plot = self_or_cls.get_plot(obj)
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py", line 135, in get_plot
plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer, **kwargs)
File "/home/python3.6/site-packages/holoviews/plotting/renderer.py", line 207, in get_plot
plot.update(init_key)
File "/home/python3.6/site-packages/holoviews/plotting/plot.py", line 595, in update
return self.initialize_plot()
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/plot.py", line 995, in initialize_plot
subplots = subplot.initialize_plot(ranges=ranges, plots=shared_plots)
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/plot.py", line 1115, in initialize_plot
adjoined_plots.append(subplot.initialize_plot(ranges=ranges, plots=passed_plots))
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 2058, in initialize_plot
self._update_ranges(element, ranges)
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 747, in _update_ranges
xfactors, yfactors = self._get_factors(element, ranges)
File "/home/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 2031, in _get_factors
xfactors = np.concatenate(xfactors)
ValueError: all the input arrays must have same number of dimensions
答案 0 :(得分:0)
是的,HLine是执行此操作的正确方法,但不幸的是,目前HoloViews中对分类轴的支持受到限制,并且将不允许此类覆盖。对于未完成的alternative implementation for categorical axes,有一些工作可以解决此问题。同时,我假设您可以添加一个custom hook,但这很难弄清楚。
请注意,无论如何,hv.Layout(boxwhisker)
都无法像上面那样工作;它应该是hv.Layout([boxwhisker])
或仅仅是boxwhisker
(因为Layout需要一个列表,但是在这里您甚至不需要布局,因为您只有一个项目)。