Open LinuxIsCool opened 1 year ago
I can reproduce it with the code given above.
Only plotting the bar returns this:
Where all bars are plotted over each other. Transposing the DataFrame gives a more desirable look:
Which is able to be used with hv.Text
:
I'm getting a similar problem in a different situation when trying to compose two bar plots using + operator.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/viewable.py:591, in Renderable._preprocess(self, root, changed, old_models)
590 try:
--> 591 hook(self, root, changed, old_models)
592 except TypeError:
TypeError: link_axes() takes 2 positional arguments but 4 were given
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/IPython/core/formatters.py:974, in MimeBundleFormatter.__call__(self, obj, include, exclude)
971 method = get_real_method(obj, self.print_method)
973 if method is not None:
--> 974 return method(include=include, exclude=exclude)
975 return None
976 else:
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/core/dimension.py:1287, in Dimensioned._repr_mimebundle_(self, include, exclude)
1280 def _repr_mimebundle_(self, include=None, exclude=None):
1281 """
1282 Resolves the class hierarchy for the class rendering the
1283 object using any display hooks registered on Store.display
1284 hooks. The output of all registered display_hooks is then
1285 combined and returned.
1286 """
-> 1287 return Store.render(self)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/core/options.py:1423, in Store.render(cls, obj)
1421 data, metadata = {}, {}
1422 for hook in hooks:
-> 1423 ret = hook(obj)
1424 if ret is None:
1425 continue
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/ipython/display_hooks.py:280, in pprint_display(obj)
278 if not ip.display_formatter.formatters['text/plain'].pprint:
279 return None
--> 280 return display(obj, raw_output=True)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/ipython/display_hooks.py:251, in display(obj, raw_output, **kwargs)
249 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
250 with option_state(obj):
--> 251 output = layout_display(obj)
252 elif isinstance(obj, (HoloMap, DynamicMap)):
253 with option_state(obj):
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/ipython/display_hooks.py:142, in display_hook.<locals>.wrapped(element)
140 try:
141 max_frames = OutputSettings.options['max_frames']
--> 142 mimebundle = fn(element, max_frames=max_frames)
143 if mimebundle is None:
144 return {}, {}
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/ipython/display_hooks.py:216, in layout_display(layout, max_frames)
213 max_frame_warning(max_frames)
214 return None
--> 216 return render(layout)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/ipython/display_hooks.py:69, in render(obj, **kwargs)
66 if renderer.fig == 'pdf':
67 renderer = renderer.instance(fig='png')
---> 69 return renderer.components(obj, **kwargs)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/plotting/renderer.py:397, in Renderer.components(self, obj, fmt, comm, **kwargs)
394 embed = (not (dynamic or streams or self.widget_mode == 'live') or config.embed)
396 if embed or config.comms == 'default':
--> 397 return self._render_panel(plot, embed, comm)
398 return self._render_ipywidget(plot)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/holoviews/plotting/renderer.py:404, in Renderer._render_panel(self, plot, embed, comm)
402 doc = Document()
403 with config.set(embed=embed):
--> 404 model = plot.layout._render_model(doc, comm)
405 if embed:
406 return render_model(model, comm)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/viewable.py:736, in Viewable._render_model(self, doc, comm)
734 if comm is None:
735 comm = state._comm_manager.get_server_comm()
--> 736 model = self.get_root(doc, comm)
738 if self._design and self._design.theme.bokeh_theme:
739 doc.theme = self._design.theme.bokeh_theme
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/layout/base.py:305, in Panel.get_root(self, doc, comm, preprocess)
301 def get_root(
302 self, doc: Optional[Document] = None, comm: Optional[Comm] = None,
303 preprocess: bool = True
304 ) -> Model:
--> 305 root = super().get_root(doc, comm, preprocess)
306 # ALERT: Find a better way to handle this
307 if hasattr(root, 'styles') and 'overflow-x' in root.styles:
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/viewable.py:660, in Renderable.get_root(self, doc, comm, preprocess)
658 root = self._get_model(doc, comm=comm)
659 if preprocess:
--> 660 self._preprocess(root)
661 else:
662 root = wrapper.get_root(doc, comm, preprocess)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/viewable.py:593, in Renderable._preprocess(self, root, changed, old_models)
591 hook(self, root, changed, old_models)
592 except TypeError:
--> 593 hook(self, root)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/panel/pane/holoviews.py:872, in link_axes(root_view, root_model)
870 if tag in fig.x_range.tags and axis is not fig.x_range:
871 if hasattr(axis, 'factors'):
--> 872 axis.factors = list(unique_iterator(axis.factors+fig.x_range.factors))
873 fig.x_range = axis
874 p.handles['x_range'] = axis
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/bokeh/core/has_props.py:327, in HasProps.__setattr__(self, name, value)
325 properties = self.properties(_with_props=True)
326 if name in properties:
--> 327 return super().__setattr__(name, value)
329 descriptor = getattr(self.__class__, name, None)
330 if isinstance(descriptor, property): # Python property
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/bokeh/core/property/descriptors.py:332, in PropertyDescriptor.__set__(self, obj, value, setter)
329 class_name = obj.__class__.__name__
330 raise RuntimeError(f"{class_name}.{self.name} is a readonly property")
--> 332 value = self.property.prepare_value(obj, self.name, value)
333 old = self._get(obj)
334 self._set(obj, old, value, setter=setter)
File ~/.cache/pypoetry/virtualenvs/alloha-S7RXN1yG-py3.10/lib/python3.10/site-packages/bokeh/core/property/bases.py:364, in Property.prepare_value(self, owner, name, value, hint)
362 else:
363 obj_repr = owner if isinstance(owner, HasProps) else owner.__name__
--> 364 raise ValueError(f"failed to validate {obj_repr}.{name}: {error}")
366 if isinstance(owner, HasProps):
367 obj = owner
ValueError: failed to validate FactorRange(id='p14208', ...).factors: expected an element of either Seq(String), Seq(Tuple(String, String)) or Seq(Tuple(String, String, String)), got [('0xe6424ab2', 'QF Matched + SME'), ('0xe6424ab2', 'QF Matched'), ('0xe6424ab2', 'QF Unmatched'), ('0x4cd41869', 'QF Matched + SME'), ('0x4cd41869', 'QF Matched'), ('0x4cd41869', 'QF Unmatched'), ('0xdd9b885d', 'QF Matched + SME'), ('0xdd9b885d', 'QF Matched'), ('0xdd9b885d', 'QF Unmatched'), ('0x8d6f0c7b', 'QF Matched + SME'), ('0x8d6f0c7b', 'QF Matched'), ('0x8d6f0c7b', 'QF Unmatched'), ('0xa9bdf738', 'QF Matched + SME'), ('0xa9bdf738', 'QF Matched'), ('0xa9bdf738', 'QF Unmatched'), ('0xe8249a10', 'QF Matched + SME'), ('0xe8249a10', 'QF Matched'), ('0xe8249a10', 'QF Unmatched'), ('0x64a30a4b', 'QF Matched + SME'), ('0x64a30a4b', 'QF Matched'), ('0x64a30a4b', 'QF Unmatched'), ('0x97589cd1', 'QF Matched + SME'), ('0x97589cd1', 'QF Matched'), ('0x97589cd1', 'QF Unmatched'), ('0x23387567', 'QF Matched + SME'), ('0x23387567', 'QF Matched'), ('0x23387567', 'QF Unmatched'), ('0xec026845', 'QF Matched + SME'), ('0xec026845', 'QF Matched'), ('0xec026845', 'QF Unmatched'), ('0xf1f4942d', 'QF Matched + SME'), ('0xf1f4942d', 'QF Matched'), ('0xf1f4942d', 'QF Unmatched'), ('0x72b0d6a6', 'QF Matched + SME'), ('0x72b0d6a6', 'QF Matched'), ('0x72b0d6a6', 'QF Unmatched'), ('0x5351510d', 'QF Matched + SME'), ('0x5351510d', 'QF Matched'), ('0x5351510d', 'QF Unmatched'), ('0x10b3f00e', 'QF Matched + SME'), ('0x10b3f00e', 'QF Matched'), ('0x10b3f00e', 'QF Unmatched'), ('0xc401c980', 'QF Matched + SME'), ('0xc401c980', 'QF Matched'), ('0xc401c980', 'QF Unmatched'), ('0xcf3165f4', 'QF Matched + SME'), ('0xcf3165f4', 'QF Matched'), ('0xcf3165f4', 'QF Unmatched'), '0xe6424ab2', '0x4cd41869', '0xdd9b885d', '0x8d6f0c7b', '0xa9bdf738', '0xe8249a10', '0x64a30a4b', '0x97589cd1', '0x23387567', '0xec026845', '0xf1f4942d', '0x72b0d6a6', '0x5351510d', '0x10b3f00e', '0xc401c980', '0xcf3165f4']
:Layout
.Bars.I :Bars [projectId,Variable] (value)
.Overlay.I :Overlay
.Bars.I :Bars [projectId] (Percentage Boost)
.HLine.I :HLine [x,y]
Can you share a minimal, reproducible example (MRE)?
Can you share a minimal, reproducible example (MRE)?
Yep!
Here you go:
import pandas as pd
import hvplot.pandas
import holoviews as hv
df = pd.DataFrame([[1,2,3,4,5],[1,2,3,4,5]])
df.hvplot.bar(y=['0','1']).opts(multi_level=False) + df.hvplot.bar(y='0')
Looking at the error, I can see it happens in Panel, so the fix maybe be needed there. As a work-around for now you can
import pandas as pd
import hvplot.pandas
import holoviews as hv
df = pd.DataFrame([[1,2,3,4,5],[1,2,3,4,5]])
(df.hvplot.bar(y=['0','1']).opts(multi_level=False) + df.hvplot.bar(y='0')).opts(shared_axes=False)
ALL software version info
Python 3.10.6 hvplot==0.8.3 holoviews==1.15.4 bokeh==2.4.3 jupyterlab==3.6.3
Description of expected behavior and the observed behavior
Should be able to add text to a bar chart as described here: https://stackoverflow.com/questions/46223037/add-text-annotations-to-each-data-point-in-holoviews-plot
Complete, minimal, self-contained example code that reproduces the issue