holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.08k stars 105 forks source link

hvplot.hist(..., logy=True) is broken #1351

Closed stuarteberg closed 3 months ago

stuarteberg commented 3 months ago

The hvplot.hist() function cannot be used with the logy option, even when all bins are populated and therefore ought to have non-infinite log values.

ALL software version info

relevant package versions ``` $ conda list | grep -E 'python|numpy|^pandas|bokeh|holo|hvplot|jupyter' bokeh 3.4.1 pyhd8ed1ab_0 conda-forge brotli-python 1.1.0 py312h30efb56_1 conda-forge holoviews 1.18.3 pyhd8ed1ab_0 conda-forge hvplot 0.10.0 pyhd8ed1ab_0 conda-forge ipython 8.24.0 pyh707e725_0 conda-forge jupyter-lsp 2.2.5 pyhd8ed1ab_0 conda-forge jupyter_bokeh 4.0.4 pyhd8ed1ab_0 conda-forge jupyter_client 8.6.2 pyhd8ed1ab_0 conda-forge jupyter_core 5.7.2 py312h7900ff3_0 conda-forge jupyter_events 0.10.0 pyhd8ed1ab_0 conda-forge jupyter_server 2.14.0 pyhd8ed1ab_0 conda-forge jupyter_server_terminals 0.5.3 pyhd8ed1ab_0 conda-forge jupyterlab 4.2.1 pyhd8ed1ab_0 conda-forge jupyterlab_pygments 0.3.0 pyhd8ed1ab_1 conda-forge jupyterlab_server 2.27.2 pyhd8ed1ab_0 conda-forge jupyterlab_widgets 3.0.11 pyhd8ed1ab_0 conda-forge libboost-python 1.82.0 py312hfb10629_6 conda-forge libboost-python-devel 1.82.0 py312h8da182e_6 conda-forge msgpack-python 1.0.8 py312h2492b07_0 conda-forge neuprint-python 0.4.26+8.gd487a3c dev_0 numpy 1.26.4 py312heda63a1_0 conda-forge openmesh-python 1.2.1 py312hfb8ada1_4 flyem-forge pandas 2.2.2 py312h1d6d2e6_1 conda-forge python 3.12.3 hab00c5b_0_cpython conda-forge python-blosc 1.11.1 py312hfb8ada1_0 conda-forge python-dateutil 2.9.0 pyhd8ed1ab_0 conda-forge python-fastjsonschema 2.19.1 pyhd8ed1ab_0 conda-forge python-json-logger 2.0.7 pyhd8ed1ab_0 conda-forge python-snappy 0.7.1 pyh48db8ab_1 conda-forge python-tzdata 2024.1 pyhd8ed1ab_0 conda-forge python_abi 3.12 4_cp312 conda-forge types-python-dateutil 2.9.0.20240316 pyhd8ed1ab_0 conda-forge ```
conda info ``` $ conda info active environment : flyem-312 active env location : /groups/flyem/proj/cluster/miniforge/envs/flyem-312 shell level : 1 user config file : /groups/flyem/home/bergs/.condarc populated config files : /groups/flyem/proj/cluster/miniforge/.condarc conda version : 24.5.0 conda-build version : 24.3.0 python version : 3.8.13.final.0 solver : libmamba (default) virtual packages : __archspec=1=sapphirerapids __conda=24.5.0=0 __glibc=2.34=0 __linux=5.14.0=0 __unix=0=0 base environment : /groups/flyem/proj/cluster/miniforge (writable) conda av data dir : /groups/flyem/proj/cluster/miniforge/etc/conda conda av metadata url : None channel URLs : https://conda.anaconda.org/flyem-forge/linux-64 https://conda.anaconda.org/flyem-forge/noarch https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch package cache : /groups/flyem/proj/cluster/miniforge/pkgs /groups/flyem/home/bergs/.conda/pkgs envs directories : /groups/flyem/proj/cluster/miniforge/envs /groups/flyem/home/bergs/.conda/envs platform : linux-64 user-agent : conda/24.5.0 requests/2.28.1 CPython/3.8.13 Linux/5.14.0-362.8.1.el9_3.x86_64 rocky/9.3 glibc/2.34 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8 UID:GID : 50328:93098 netrc file : None offline mode : False ```

Description of expected behavior and the observed behavior

When using logy=True, no bars are shown, and a warning is given. (See below.)

Complete, minimal, self-contained example code that reproduces the issue

import pandas as pd
import hvplot.pandas

data = pd.Series([1, 1, 2, 2, 2, 3, 3, 3])
data.hvplot.hist(bins=[0,2,4], logy=True)

Stack traceback and/or browser JavaScript console output

WARNING:param.HistogramPlot08409: Logarithmic axis range encountered value less than or equal to zero, please supply explicit lower bound to override default of 0.010.

Screenshots or screencasts of the bug in action

image
hoxbro commented 3 months ago

Thank you for the issue.

This is a limitation in Bokeh, https://github.com/bokeh/bokeh/issues/6536 and is also tracked in HoloViews here.

stuarteberg commented 3 months ago

@hoxbro Thanks for the response. I'm happy to close this if it's truly a duplicate of the two issues you linked to.

I'm confused, though: Those issues pertain to data with at least one empty bin. In my case, there are no empty bins, so the minimum y-value should be non-negative, even after taking the log.

In [12]: data = [1, 1, 2, 2, 2, 3, 3, 3]
    ...: y = np.histogram(data, bins=[1,2,4])[0]
    ...: np.log(y)
Out[12]: array([0.69314718, 1.79175947])
hoxbro commented 3 months ago

The zero referred to is the bottom of the rectangles used for the histogram bars, not the empty space between bars.

stuarteberg commented 3 months ago

Ah, I see. So it's not the y-values that matter... that would be the top of the bars. But every bar has the same bottom position, and it's 0 for all of them.

Thanks for the clarification. Closing this.

ampilnick commented 2 months ago

Please don't close this issue until it will not fixed! Now hvplot.hist(..., logy=True) is still broken.

maximlt commented 2 months ago

Hi @ampilnick, I'm -1 on re-opening this issue as it is already tracked in https://github.com/holoviz/holoviews/issues/2591 and https://github.com/bokeh/bokeh/issues/6536. I have added the hvplot label to https://github.com/holoviz/holoviews/issues/2591 to let the maintainers know that this also affects hvPlot.