2 回答
TA贡献2003条经验 获得超2个赞
如果你想对外部索引进行排序,你可以.sort(dimension, reverse=True)在你的hv.Bars对象上使用。但是,对内部索引进行排序将需要您显式设置维度值:
from bokeh.io import show
import holoviews as hv
hv.extension("bokeh")
df = df.groupby(["set", "flag"])["id"].count().reset_index()
count_bars = hv.Bars(df, kdims=["set","flag"], vdims="id")
plot = (count_bars
.opts(hooks=[hook1], title="IDs",invert_axes=True, width=500, padding=2)
.redim.values(flag=["Y", "N"]) # Inverting the axes flips this order. This produces N, Y vertically
.sort("set", reverse=True)
)
bokeh_obj = hv.render(plot, backend="bokeh")
show(bokeh_obj)
生产:
TA贡献1799条经验 获得超8个赞
作为快速修复/解决方法,我已将索引反转为按 的顺序出现df,但我认为这应该在holoviews将来修复
df['indexn'] = df.index
df.indexn = df.indexn.values[::-1]
order = df.sort_values(by='indexn').set
order1 = df.sort_values(by='indexn').flag
count_bars = hv.Bars(df, kdims=["set","flag"], vdims="id").redim.values(set=order,flag=order1)
添加回答
举报