0

I am struggling to get legible tick labels in a holoviews violin or box plot. Below are what I've tried, with comments describing how each fails to get the job done. I don't understand how to use the documented xtick and/or xformatter options for viollin and box

import hvplot
import hvplot.xarray
import xarray as xr
import numpy as np
from bokeh.models import BasicTickFormatter

if __name__ == "__main__":
    # make a dummy xarray dataset with two dimensions
    dim1_size = 10000
    dim2_size = 50
    xds = xr.Dataset(
        {"values": (("dim1", "dim2"), np.random.random((dim1_size, dim2_size)))},
        coords={"dim1": np.arange(dim1_size), "dim2": np.arange(dim2_size)},
    )

    # this works, but the horizontal axis labels overrun and are illegible
    p = xds.hvplot.violin("values", by="dim2")
    hvplot.show(p)

    # --------------------------------------------------
    # for each of the following, a server starts and no plot appears at all

    # p = xds.hvplot.violin("values", by="dim2", xticks=[0, 25, 50])
    # hvplot.show(p)

    # p = xds.hvplot.violin("values", by="dim2").opts(xticks=[1, 25, 50])
    # hvplot.show(p)

    # formatter = BasicTickFormatter()
    # p = xds.hvplot.violin("values", by="dim2").opts(xformatter=formatter)
    # hvplot.show(p)

  • It looks to me that this is a [duplicate](https://stackoverflow.com/questions/76175104/method-to-change-xticks-for-bokeh-bar-plo) and is related to this [bug report](https://github.com/holoviz/hvplot/issues/1066) in the `hvplot` project. See [this tutorial](https://hvplot.holoviz.org/reference/pandas/violin.html). It is possible to modify the `xticks`, if you modify the source beforehand. – mosc9575 May 09 '23 at 07:16
  • Thanks @mosc9575. I'm not sure that it's strictly [a duplicate of that post](https://stackoverflow.com/questions/76175104/method-to-change-xticks-for-bokeh-bar-plo). With a curve or barplot one could pre-calculate beforehand, but with a grouped boxplot or violin there's quite a bit of calculation done inside the method - one is not simply passing (x, y) pairs to be plotted. – Timothy W. Hilton May 11 '23 at 01:13
  • 1
    @mosc9575 I think you're right that it's likely the same underlying set of problems as [hvplot issue 975](https://github.com/holoviz/hvplot/issues/975), referenced from [issue 1066](https://github.com/holoviz/hvplot/issues/1066) that you mentioned. I've added this example to that thread. – Timothy W. Hilton May 11 '23 at 01:14

0 Answers0