empiricaldist plotting functions

Copyright 2019 Allen Downey

BSD 3-clause license: https://opensource.org/licenses/BSD-3-Clause

In [1]:
%matplotlib inline

import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
In [2]:
from empiricaldist import Pmf
In [3]:
pmf = Pmf.from_seq([1, 2, 2, 4, 5], name='example')
In [4]:
pmf.plot()
plt.legend();
No handles with labels found to put in legend.
In [5]:
pmf.bar()
plt.legend();
No handles with labels found to put in legend.
In [6]:
xs = [1,2,3,4]
ys = [0.15, 0.35, 0.25, 0.2]

pmf.plot()

plt.plot(xs, ys)
Out[6]:
[<matplotlib.lines.Line2D at 0x7f20eee1e410>]
In [7]:
cdf = pmf.make_cdf()
cdf.plot()
plt.legend();
No handles with labels found to put in legend.
In [8]:
cdf.step()
plt.legend();
No handles with labels found to put in legend.
In [9]:
surv = cdf.make_surv()
surv.plot()
plt.legend();
No handles with labels found to put in legend.
In [10]:
surv = cdf.make_surv()
surv.step()
plt.legend();
No handles with labels found to put in legend.
In [11]:
haz = surv.make_hazard()
haz.plot()
plt.legend();
No handles with labels found to put in legend.
In [12]:
haz.bar()
plt.legend();
No handles with labels found to put in legend.

Replicating a problem with plotting Pmfs

In [13]:
unbiased = np.array([ 5,  6, 12,  7,  8,  6,  6,  9,  8,  4,  3,  5,  5,  7,  5,  7,  4,
        4,  3,  6,  3,  5, 10,  1,  7,  4,  8,  2,  9,  6,  5,  5,  9, 11,
       11,  3,  9,  1, 10,  1,  6,  6,  5,  8,  7,  7,  4,  7,  2,  1,  3,
        1,  6,  3,  1,  1,  2,  2,  1,  2,  2,  1])
In [14]:
pmf = Pmf.from_seq(unbiased)
In [15]:
pmf.bar(label='')
In [16]:
from scipy.stats import poisson

mean = np.mean(unbiased)

qs = np.arange(1, 13)
ps = poisson.pmf(qs, mean)
plt.plot(qs, ps, color='C1', label='model')
Out[16]:
[<matplotlib.lines.Line2D at 0x7f20ee1828d0>]
In [17]:
pmf.bar()
plt.plot(qs, ps, color='C1', label='model')
Out[17]:
[<matplotlib.lines.Line2D at 0x7f20ee0e5d90>]