为什么为什么
hv.Scatter(src, x, y) << hv.Histogram(np.histogram(src[y], 20)) << hv.Histogram(np.histogram(src[x], 20))
和
hv.Scatter(src, x, y).hist(num_bins=20, dimension=[x, y])
在轴和悬停标签方面表现不同?我需要向前者提供什么论据才能使其表现得像后者?
具体来说,如果我有下面的代码 MWE,
scatter_hist(ds, [('x', 'Apples')], [('y', 'Oranges'), ('z', 'Sauce')], ['x', 'y'])
它使用.histogram
在左边产生结果,而
scatter_hist2(ds, [('x', 'Apples')], [('y', 'Oranges'), ('z', 'Sauce')], ['x', 'y'])
它使用<< hv.Histogram
在右边产生结果:
请注意,后者中的轴和悬停不使用提供的数据标签,x
而不是使用Oranges
or Apples
。
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
xs = np.random.rand(100)
ys = np.random.rand(100)
df = pd.DataFrame({'x': xs, 'y': ys, 'z': xs*ys})
ds = hv.Dataset(df)
def scatter_hist(src, x, y, dims):
p = hv.Scatter(src, x, y).hist(num_bins=20, dimension=dims).opts(
opts.Scatter(show_title=False, tools=['hover','box_select']),
opts.Histogram(tools=['hover','box_select']),
opts.Layout(shared_axes=True, shared_datasource=True, merge_tools=True)
)
return p
def scatter_hist2(src, x, y, dims):
p = (hv.Scatter(src, x, y) << hv.Histogram(np.histogram(src[dims[1]], 20)) << hv.Histogram(np.histogram(src[dims[0]], 20)) ).opts(
opts.Scatter(show_title=False, tools=['hover','box_select']),
opts.Histogram(tools=['hover','box_select']),
opts.Layout(shared_axes=True, shared_datasource=True, merge_tools=True)
)
return p