How to control bar order in using holoviews.Bars?

How does one control the order that Bars appear in a Bars plot?

Modifying the xticks as shown here does not seem to work for text based bars.
For example: How does one modify the order of countries in the last plot in this page so that the first bar will be fore “United States” , the second “United Kingdom” and the third “Australia”?

1 Like

The solution to this problem was given by Philip Rudiger online and I am showing it here with an example. In short .redim.values(AxisX=[List of categories]) should be used when Axis is the name of the parameter used for the x axis. Here is code that demonstrates this for bars with and without changing axis order:

import panel
import holoviews
from holoviews import opts
from bokeh.resources import INLINE


holoviews.extension('bokeh')
data = {
    'Param': ['b','c', 'a'],
    'Value': [1, 0, 0.5],
    'alpha': [0.5, 1, 0.3],
    'color': ['red', 'blue', 'green'],
    'marker': ['circle', 'triangle', 'diamond'],
    'size': [15, 25, 40]
}

opts.defaults(opts.Points(padding=0.1, size=8, line_color='black'))

Plot1 = holoviews.Bars(data, kdims=['Param'], vdims=['Value', 'color']).redim.values(Param=['a','b','c']).opts( color='color', axiswise=True)
Plot2 = holoviews.Bars(data, kdims=['Param'], vdims=['Value', 'color']).opts( color='color', axiswise=True)

Out1=panel.panel(Plot1)
Out2=panel.panel(Plot2)

Out = panel.Column(Out1,Out2)
Out.save('TestOut', resources=INLINE) 

The output looks like: