I would like to produce a step plot with a categorical x axis!
import hvplot.pandas
import numpy as np
import pandas as pd
import panel as pn
df = pd.DataFrame({'x': list('abcd'), 'y': np.random.rand(4)})
chart = df.hvplot.step(x='x', y='y')
view = pn.panel(chart)
view.servable()
But I get the error:
2023-12-14 10:46:26,173 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x7f28f38b8f70>: unsupported operand type(s) for -: 'str' and 'str'
File 'element.py', line 1017, in pts_to_midstep:
steps[1:-1:2] = steps[2::2] = x[:-1] + (x[1:] - x[:-1])/2 Traceback (most recent call last):
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/bokeh/application/handlers/code_runner.py", line 229, in run
exec(self._code, module.__dict__)
File "/home/ygg/Workspace/TEC/alloha/research/categorical_step.py", line 12, in <module>
view.servable()
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/viewable.py", line 394, in servable
self.server_doc(title=title, location=location) # type: ignore
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/viewable.py", line 1023, in server_doc
model = self.get_root(doc)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/pane/base.py", line 421, in get_root
root_view, root = self._get_root_model(doc, comm, preprocess)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/pane/base.py", line 350, in _get_root_model
root = self.layout._get_model(doc, comm=comm)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/layout/base.py", line 177, in _get_model
objects, _ = self._get_objects(model, [], doc, root, comm)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/layout/base.py", line 159, in _get_objects
child = pane._get_model(doc, root, model, comm)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/pane/holoviews.py", line 414, in _get_model
plot = self._render(doc, comm, root)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/panel/pane/holoviews.py", line 509, in _render
return renderer.get_plot(self.object, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/bokeh/renderer.py", line 68, in get_plot
plot = super().get_plot(obj, doc, renderer, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/renderer.py", line 240, in get_plot
plot.update(init_key)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/plot.py", line 955, in update
return self.initialize_plot()
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/bokeh/element.py", line 1887, in initialize_plot
self._init_glyphs(plot, element, ranges, source)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/bokeh/element.py", line 1806, in _init_glyphs
data, mapping, style = self.get_data(element, ranges, style)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/plotting/bokeh/chart.py", line 358, in get_data
element = interpolate_curve(element, interpolation=self.interpolation)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/param/parameterized.py", line 4428, in __new__
return inst.__call__(*args,**params)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/operation.py", line 220, in __call__
return element.apply(self, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/accessors.py", line 44, in pipelined_call
result = __call__(*args, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/accessors.py", line 203, in __call__
new_obj = apply_function(self._obj, **inner_kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/operation.py", line 214, in __call__
return self._apply(element)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/operation.py", line 141, in _apply
ret = self._process(element, key)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/operation/element.py", line 1062, in _process
return element.map(self._process_layer, Element)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/data/__init__.py", line 196, in pipelined_fn
result = method_fn(*args, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/data/__init__.py", line 1213, in map
return super().map(*args, **kwargs)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/core/dimension.py", line 697, in map
return map_fn(self) if applies else self
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/operation/element.py", line 1056, in _process_layer
xs, dvals = INTERPOLATE_FUNCS[self.p.interpolation](x, dvals)
File "/home/ygg/.cache/pypoetry/virtualenvs/alloha-qEy3MGg--py3.10/lib/python3.10/site-packages/holoviews/operation/element.py", line 1017, in pts_to_midstep
steps[1:-1:2] = steps[2::2] = x[:-1] + (x[1:] - x[:-1])/2
TypeError: unsupported operand type(s) for -: 'str' and 'str'
The reason for doing this is that I would like to overlay a step chart on top of a bar chart!