0
votes

I am making a simple Curve with values on the x-axis expressed in seconds (SI units) with values on the order of nanoseconds.

I would like to format the axis ticks using a hv.Dimension object as explained in How to control Holoviews y-tick format?. This example works perfectly when using the matplotlib backend but does not work when using the (default) bokeh backend.

I currently have a custom formatter that multiplies all my values by the desired amount and specifies the right units.

xs = np.linspace(0, 15e-6, 500)
xfmt = lambda x: round(x*1e6, ndigits=3)
c = hv.Curve({'x':xs, 'y':step_lowpass(xs, tau=.1e-6)}, 
             kdims=[hv.Dimension('x', label='Time', unit='$\mu$s', value_format=xfmt)])

This works perfectly when using the matplotlib backend, however when using the Bokeh backend it does not work, giving the following warning:

WARNING:root:main: x dimension formatter could not be converted to tick formatter. Pyscript raised an error: list index out of range

And not using the formatter. I have also tried directly specifying a bokeh.models.formatters.FuncTickFormatter object as the argument for the value_format, however this does not work as these object are not directly callable but instead contain the code required to format the tick as an attribute.

1

1 Answers

3
votes

value_format is a python function that been convert to javascript code by flexx.pyscript.py2js(). Since there is a bug in holoviews, that when you have multiple operator, the javascript will be failed.

You can use the following function to bypass the bug:

def xfmt(x):
    return "%f" % (Math.round(eval("x * 1e9")) / 10e3)