Plot Poisson PMF Holoviews

Viewed 40

Having a bit of difficulty plotting the out put of my poisson PMF using holoviews. Using a matplot lib example I am after this:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import hvplot.pandas, holoviews as hv
from holoviews import opts
from scipy.stats import poisson
pd.options.plotting.backend = 'holoviews'

sales = np.random.randint(0, 100, size=100)

poisson_pd = poisson.pmf(sales, 4)

ig, ax = plt.subplots(1, 1, figsize=(8, 6))
ax.plot(sales, poisson_pd, 'bo', ms=8, label='poisson pmf')
plt.ylabel("Probability", fontsize="18")
plt.xlabel("Sales", fontsize="18")
plt.title("Poisson Distribution - Sales Vs Probability", fontsize="18")
ax.vlines(sales, 0, poisson_pd, colors='b', lw=2, alpha=0.5)

enter image description here

However, when I try doing a similar thing using holoviews I end up with a mess of a chart. The code I got from this site and I have modified a bit (https://www.kaggle.com/code/stephen924/discrete-probability-distributions-part-1/notebook)

mu = 4
sales = np.random.randint(0, 100, size=100)
hist = np.histogram(sales, density=False, bins=6)
pmf = stats.poisson.pmf(sales,mu)
pois = hv.Histogram(pmf, sales).opts(width = 800, height = 800).opts(tools = ['hover'])
pois

enter image description here

Like its kind of correct, but I think there is substantial overlapping going on. I'm fine with it being a histogram instead of the matplotlib chart, however, would be great to know how to clean this up. Or if anyone has any suggestions, what would be a better way to produce this kind of chart.

Thanks for any help offered!

0 Answers
Related