holoviz / holoviz/hvplot

HvPlot Bokeh - Violin plot behaving strangely in log scale

Open
#1,085 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

Python 3.9
bokeh 3.1.1
holoviews 1.16.1
hvplot 0.8.3
pandas 2.0.2
numpy 1.24.3

Hello,
I am trying to visualize data as a violin plot using bokeh extension. It works fine in linear scale but things look messed up in log scale, when `logy=True` is activated in the plotting function.
I would expect to simply see the violin plot as corresponding to a distribution computation of data after applying a `log10` function, plotting it and then changing the visu scale to match what is required to display.
However, it looks like the `violin` function first computes the distribution and then only applies the `log10` function, which leads to a bin size problem. Indeed, as for a histogram plot, if one requires a histogram in log scale, the `log10` function is applied to the bins after having computed the distribution. Normally there is nothing wrong with this, except that in violin plot, it has the effect to truncate the distribution, and consequently this distribution does not engulf the box plot, which does not make any sense.

I wonder if this is a bug or if there is a workaround this difficulty.

A minimal code example is shown below:

```
import hvplot.pandas

import pandas as pd
import numpy as np

hvplot.extension('bokeh')

temp = [3.021e+00, 1.726e+00, 2.092e+00, 1.721e+00, np.nan, 3.182e+00, 8.335e+00,
9.851e+00, 9.743e+00, 3.153e+01, np.nan, 2.458e+01, 1.138e+01, 9.886e+01,
1.638e+01, 1.084e+00, 1.573e+00, 2.486e-01, 4.257e-01, 2.447e-01, 3.540e-01,
3.644e-01, 3.296e-01, 3.450e-01, 2.739e-01, 3.404e-01, 4.427e-01, 8.187e-01,
4.360e-01, 3.556e-01, 3.107e+00, 9.722e-01, 1.572e+00, 7.006e-01, 2.344e-01,
9.597e-01, 1.372e-01, 2.530e-01, 1.100e+00, 5.791e+00, 1.093e+01, 4.249e+00,
4.841e+00, 5.234e+00, 1.355e+01, 1.423e+01, 2.478e+01, np.nan, 4.721e+01,
np.nan, 9.234e+01, np.nan, 1.045e+02, np.nan, 8.989e+01, np.nan,
9.330e+01, np.nan, 1.151e+02, np.nan, 2.193e+02, np.nan, 1.705e+02,
np.nan, 3.835e+02, np.nan, 1.689e+03, np.nan, 1.879e+03, np.nan,
1.898e+03, np.nan, 2.374e+03, np.nan, 3.079e+03, 3.611e+03, 3.926e+03]

test = pd.Series(temp)

plot = test.hvplot.violin(logy=True)
hvplot.show(plot)

```
A few screenshots:

What the code outputs when `logy=False`:
![image](https://github.com/holoviz/hvplot/assets/38283399/eb55f2c9-064b-4e91-aead-97d7ed1176dc)
What it outputs when `logy=True`:
![image](https://github.com/holoviz/hvplot/assets/38283399/18fe743b-cdec-4c9c-92a9-2658a8b8f2b2)
What it should output when `logy=True` (I obtained this figure by applying `np.log10` to my data and turning `logy=False`):
![image](https://github.com/holoviz/hvplot/assets/38283399/618e0750-537c-4ee1-80dc-3ea8b52ed747)

Hope this is clear and that my point is understood !
Cheers !

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.