In [2]:
% matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import plotly.plotly as py

Bernoulli Random Variable

The PMF for Bernoulli is

bernoulli.pmf(k) = 1 - p, if k = 0

             = p, if k = 1

In [ ]:
from scipy.stats import bernoulli

In [9]:
p = 0.3 # probability

# plotting the bernoulli
fig, ax = plt.subplots(1, 1)
x = np.arange(bernoulli.ppf(0.01, p),
              bernoulli.ppf(0.99, p))
ax.plot(x, bernoulli.pmf(x, p), 'bo', ms=8, label='bernoulli pmf')

ax.vlines(x, 0, bernoulli.pmf(x, p), colors='b', lw=5, alpha=0.5)
py.iplot_mpl(fig)


C:\Anaconda3.6\lib\site-packages\plotly\matplotlylib\renderer.py:445: UserWarning:

Dang! That path collection is out of this world. I totally don't know what to do with it yet! Plotly can only import path collections linked to 'data' coordinates

Out[9]: