Closed MarcSkovMadsen closed 1 day ago
$ uv pip show holoviews hvplot bokeh numpy pandas
Name: bokeh
Version: 3.4.2
Location: /home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages
Requires: contourpy, jinja2, numpy, packaging, pandas, pillow, pyyaml, tornado, xyzservices
Required-by: holoviews, hvplot, panel
---
Name: holoviews
Version: 1.19.0
Location: /home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages
Requires: bokeh, colorcet, numpy, packaging, pandas, panel, param, pyviz-comms
Required-by: hvplot
---
Name: hvplot
Version: 0.10.0
Location: /home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages
Requires: bokeh, colorcet, holoviews, numpy, packaging, pandas, panel, param
Required-by: mt-pm-reporting
---
Name: numpy
Version: 2.0.0
Location: /home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages
Requires:
Required-by: bokeh, contourpy, holoviews, hvplot, mt-pm-reporting, pandas, pandas-stubs, pandera, pyarrow, sycamore
---
Name: pandas
Version: 2.2.2
Location: /home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages
Requires: numpy, python-dateutil, pytz, tzdata
Required-by: analytics-workspace, bokeh, holoviews, hvplot, mt-data-engineering, pandera, panel
I've also tried downgrading numpy to 1.26.1. Does not change anything for me. I've also tried downgrading bokeh to 3.4.1. Does not change anything for me.
Actually neither of the continuous examples from the Bars
documentation works for me now.
https://holoviews.org/reference/elements/bokeh/Bars.html
from datetime import datetime
import holoviews as hv
import hvplot.pandas
import pandas as pd
import panel as pn
pn.extension()
data = pd.DataFrame({"x": [0, 1, 5], "y": [0, 2, 10]})
pn.panel(hv.Bars(data, ["x"], ["y"])).servable()
data = pd.DataFrame({"x": pd.date_range("2017-01-01", "2017-01-03"), "y": [0, 2, -1]})
pn.panel(hv.Bars(data, ["x"], ["y"])).servable()
I don't have any problem with your last example (though I'm running on main on a couple of repos)
Seems like a bad solve. Can you report what you see with hv.show_versions()
in your environment?
Python : 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:35) [GCC 12.3.0] Operating system : Linux-5.15.0-1064-azure-x86_64-with-glibc2.35 Panel comms : default
holoviews : 1.19.0
bokeh : 3.4.2 colorcet : 3.1.0 cudf : - dask : - datashader : - geoviews : - hvplot : 0.10.0 ibis-framework : - IPython : - jupyter_bokeh : - jupyterlab : - matplotlib : - networkx : - notebook : - numba : - numpy : 1.26.4 pandas : 2.2.2 panel : 1.4.4 param : 2.1.1 pillow : 10.3.0 plotly : - pyarrow : 16.1.0 pyviz_comms : 3.0.2 scikit-image : - scipy : - spatialpandas : - streamz : - tsdownsample : - xarray : - None
Just created a new environment, still don't see you last problem. Can you try serving the app with python -m panel serve file.py
?
Python : 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0]
Operating system : Linux-6.9.3-76060903-generic-x86_64-with-glibc2.35
Panel comms : default
holoviews : 1.19.0
bokeh : 3.4.2
colorcet : 3.1.0
cudf : -
dask : -
datashader : -
geoviews : -
hvplot : -
ibis-framework : -
IPython : -
jupyter_bokeh : -
jupyterlab : -
matplotlib : 3.8.4
networkx : -
notebook : -
numba : -
numpy : 2.0.0
pandas : 2.2.2
panel : 1.4.4
param : 2.1.1
pillow : 10.3.0
plotly : -
pyarrow : -
pyviz_comms : 3.0.2
scikit-image : -
scipy : -
spatialpandas : -
streamz : -
tsdownsample : -
xarray : -
Hmm. I tried installing without using uv
- just using plain pip
.
Then I get back to my original problem
import panel as pn
import hvplot.pandas
from datetime import datetime
pn.extension()
KIND="bar"
positive_values = pd.DataFrame({
"time": [datetime(year,1,1) for year in range(2025, 2033)],
"value": list(range(1,9)),
})
neg_start=2024
negative_values = pd.DataFrame({
"time": [datetime(2024,1,1)],
"value": [-1]
})
pos_plot = positive_values.hvplot(x="time.year", y="value", color="green", kind=KIND)
neg_plot = negative_values.hvplot(x="time.year", y="value", color="red", kind=KIND)
plot = neg_plot*pos_plot
pn.panel(plot).servable()
ValueError: zero-size array to reduction operation minimum which has no identity
Traceback (most recent call last):
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/io/handlers.py", line 389, in run
exec(self._code, module.__dict__)
File "/home/jovyan/repos/mt-pm-reporting/script.py", line 24, in <module>
pn.panel(plot).servable()
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/viewable.py", line 394, in servable
self.server_doc(title=title, location=location) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/viewable.py", line 1001, in server_doc
model = self.get_root(doc)
^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/pane/base.py", line 420, in get_root
root_view, root = self._get_root_model(doc, comm, preprocess)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/pane/base.py", line 349, in _get_root_model
root = self.layout._get_model(doc, comm=comm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/layout/base.py", line 185, in _get_model
objects, _ = self._get_objects(model, [], doc, root, comm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/layout/base.py", line 167, in _get_objects
child = pane._get_model(doc, root, model, comm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/pane/holoviews.py", line 429, in _get_model
plot = self._render(doc, comm, root)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/panel/pane/holoviews.py", line 525, in _render
return renderer.get_plot(self.object, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/bokeh/renderer.py", line 68, in get_plot
plot = super().get_plot(obj, doc, renderer, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/renderer.py", line 239, in get_plot
plot.update(init_key)
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/plot.py", line 956, in update
return self.initialize_plot()
^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/bokeh/element.py", line 3339, in initialize_plot
child = subplot.initialize_plot(ranges, plot, plots)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/bokeh/element.py", line 2130, in initialize_plot
self._init_glyphs(plot, element, ranges, source)
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/bokeh/element.py", line 2030, in _init_glyphs
data, mapping, style = self.get_data(element, ranges, style)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/holoviews/plotting/bokeh/chart.py", line 931, in get_data
width = np.min(width)
^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 3042, in min
return _wrapreduction(a, np.minimum, 'min', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/repos/mt-pm-reporting/.venv/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation minimum which has no identity
I will close a new one focusing on that one.
I will fix that right now.
I will keep this one open then.
For future reference. I could use the color
argument to hvplot. Just not providing a list. But referencing a column
from datetime import datetime
import holoviews as hv
import hvplot.pandas
import pandas as pd
import panel as pn
pn.extension()
KIND="bar"
data = pd.DataFrame({
"time": [datetime(year,1,1) for year in range(2025, 2033)],
"value": list(range(-5,3)),
})
data["color"]="green"
data.loc[data.value<0, "color"]="red"
plot = data.hvplot(x="time.year", y="value", color="color", kind=KIND)
pn.panel(plot).servable()
I'm trying to make a
bar
plot with hvplot using timeseries data. I would like to give positive values a green bar color and negative values a red bar color to make it very clear where the changes are positive and negative.I've tried formatting my time as strings, ints and datatimes. I've tried arranging my data and using the
by
argument. I've tried setting thecolor
as a list of colors. But I cannot achieve this either because it errors or it does not display as I want.A workaround would be highly appreciated as this is the most used kindof plot in my domain.
Reproducible Example
I believe the below is a bug.
As my data is dynamically generated, I might have 0, 1 or many positive values. I should be able to handle these situations. I had something working for all situations but 1 positive value. But after upgrading my environment everything stopped working.
With the old environment I believe there was a problem here
The problem was that the case when xvals consists of 1 element is not handled well. Now I don't know. The problem is the stack trace does not give me hints of the problem that I can understand.
If you change
KIND
to"scatter"
it does not raise an exception.