How to hide/remove the axis alone without removing the axis labels in holoviews

2.3k Views Asked by At

When I add in... .opts(title="Graph",ylabel="Count",width=400,axiswise=True,xaxis='bare') xasis='bare' or xaxis=none it makes the whole axis disappear along with the labels in holoviews. How do I only remove only the axis while displaying the axis labels? Here the label is given as ylabel as axis is inverted. ylabel sets label for xaxis

Refer here for sample graph code

Also is there a way to give a main title for side-by-side plots asides the individual plot titles in holoviews.

1

There are 1 best solutions below

1
On BEST ANSWER

You'll need to dive into bokeh for this. You can do this either with a hook, or rendering the bokeh object and working with it directly:

Hook approach:

import holoviews as hv
hv.extension("bokeh")

def hook(plot, element):
    plot.state.xaxis.major_tick_line_color = None        # turn off x-axis major ticks
    plot.state.xaxis.minor_tick_line_color = None        # turn off x-axis minor ticks
    plot.state.xaxis.major_label_text_font_size = '0pt'  # turn off x-axis tick labels


df = pd.DataFrame({
    "set": list("ABABCCAD"),
    "flag": list("YYNNNYNY"),
    "id": list("DEFGHIJK"),
})

df = df.groupby(["set", "flag"])["id"].count().reset_index()
count_bars = hv.Bars(df, kdims=["set","flag"], vdims="id")

plot = (count_bars
        .opts(hooks=[hook], 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)
       )

Rendering the bokeh object and working with it:

from bokeh.io import show
import holoviews as hv
hv.extension("bokeh")
    
df = pd.DataFrame({
    "set": list("ABABCCAD"),
    "flag": list("YYNNNYNY"),
    "id": list("DEFGHIJK"),
})

df = df.groupby(["set", "flag"])["id"].count().reset_index()
count_bars = hv.Bars(df, kdims=["set","flag"], vdims="id")

plot = (count_bars
        .opts(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_figure = hv.render(plot)
bokeh_figure.xaxis.major_tick_line_color = None        # turn off x-axis major ticks
bokeh_figure.xaxis.minor_tick_line_color = None        # turn off x-axis minor ticks
bokeh_figure.xaxis.major_label_text_font_size = '0pt'  # turn off x-axis tick labels

show(bokeh_figure)

Both methods produce this plot: enter image description here