@@ -124,6 +124,8 @@ S = np.arange(1, n+1)
124124ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
125125ax.vlines(S, 0, u.pmf(S), lw=0.2)
126126ax.set_xticks(S)
127+ ax.set_xlabel('S')
128+ ax.set_ylabel('PMF')
127129plt.show()
128130```
129131
@@ -136,6 +138,8 @@ S = np.arange(1, n+1)
136138ax.step(S, u.cdf(S))
137139ax.vlines(S, 0, u.cdf(S), lw=0.2)
138140ax.set_xticks(S)
141+ ax.set_xlabel('S')
142+ ax.set_ylabel('CDF')
139143plt.show()
140144```
141145
@@ -232,6 +236,8 @@ S = np.arange(1, n+1)
232236ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
233237ax.vlines(S, 0, u.pmf(S), lw=0.2)
234238ax.set_xticks(S)
239+ ax.set_xlabel('S')
240+ ax.set_ylabel('PMF')
235241plt.show()
236242```
237243
@@ -244,6 +250,8 @@ S = np.arange(1, n+1)
244250ax.step(S, u.cdf(S))
245251ax.vlines(S, 0, u.cdf(S), lw=0.2)
246252ax.set_xticks(S)
253+ ax.set_xlabel('S')
254+ ax.set_ylabel('CDF')
247255plt.show()
248256```
249257
@@ -267,6 +275,8 @@ u_sum = np.cumsum(u.pmf(S))
267275ax.step(S, u_sum)
268276ax.vlines(S, 0, u_sum, lw=0.2)
269277ax.set_xticks(S)
278+ ax.set_xlabel('S')
279+ ax.set_ylabel('CDF')
270280plt.show()
271281```
272282
@@ -289,21 +299,13 @@ The mean and variance are:
289299``` {code-cell} ipython3
290300λ = 2
291301u = scipy.stats.poisson(λ)
292- ```
293-
294- ``` {code-cell} ipython3
295302u.mean(), u.var()
296303```
297-
298- The the expectation of Poisson distribution is $\lambda$ and the variance is also $\lambda$.
304+
305+ The expectation of the Poisson distribution is $\lambda$ and the variance is also $\lambda$.
299306
300307Here's the PMF:
301308
302- ``` {code-cell} ipython3
303- λ = 2
304- u = scipy.stats.poisson(λ)
305- ```
306-
307309``` {code-cell} ipython3
308310u.pmf(1)
309311```
@@ -314,6 +316,8 @@ S = np.arange(1, n+1)
314316ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
315317ax.vlines(S, 0, u.pmf(S), lw=0.2)
316318ax.set_xticks(S)
319+ ax.set_xlabel('S')
320+ ax.set_ylabel('PMF')
317321plt.show()
318322```
319323
@@ -386,7 +390,8 @@ for μ, σ in zip(μ_vals, σ_vals):
386390 ax.plot(x_grid, u.pdf(x_grid),
387391 alpha=0.5, lw=2,
388392 label=f'$\mu={μ}, \sigma={σ}$')
389-
393+ ax.set_xlabel('x')
394+ ax.set_ylabel('PDF')
390395plt.legend()
391396plt.show()
392397```
@@ -402,6 +407,8 @@ for μ, σ in zip(μ_vals, σ_vals):
402407 alpha=0.5, lw=2,
403408 label=f'$\mu={μ}, \sigma={σ}$')
404409 ax.set_ylim(0, 1)
410+ ax.set_xlabel('x')
411+ ax.set_ylabel('CDF')
405412plt.legend()
406413plt.show()
407414```
@@ -446,7 +453,8 @@ for μ, σ in zip(μ_vals, σ_vals):
446453 ax.plot(x_grid, u.pdf(x_grid),
447454 alpha=0.5, lw=2,
448455 label=f'$\mu={μ}, \sigma={σ}$')
449-
456+ ax.set_xlabel('x')
457+ ax.set_ylabel('PDF')
450458plt.legend()
451459plt.show()
452460```
@@ -461,6 +469,8 @@ for σ in σ_vals:
461469 label=f'$\mu={μ}, \sigma={σ}$')
462470 ax.set_ylim(0, 1)
463471 ax.set_xlim(0, 3)
472+ ax.set_xlabel('x')
473+ ax.set_ylabel('CDF')
464474plt.legend()
465475plt.show()
466476```
@@ -500,6 +510,8 @@ for λ in λ_vals:
500510 ax.plot(x_grid, u.pdf(x_grid),
501511 alpha=0.5, lw=2,
502512 label=f'$\lambda={λ}$')
513+ ax.set_xlabel('x')
514+ ax.set_ylabel('PDF')
503515plt.legend()
504516plt.show()
505517```
@@ -512,6 +524,8 @@ for λ in λ_vals:
512524 alpha=0.5, lw=2,
513525 label=f'$\lambda={λ}$')
514526 ax.set_ylim(0, 1)
527+ ax.set_xlabel('x')
528+ ax.set_ylabel('CDF')
515529plt.legend()
516530plt.show()
517531```
@@ -557,6 +571,8 @@ for α, β in zip(α_vals, β_vals):
557571 ax.plot(x_grid, u.pdf(x_grid),
558572 alpha=0.5, lw=2,
559573 label=fr'$\alpha={α}, \beta={β}$')
574+ ax.set_xlabel('x')
575+ ax.set_ylabel('PDF')
560576plt.legend()
561577plt.show()
562578```
@@ -569,6 +585,8 @@ for α, β in zip(α_vals, β_vals):
569585 alpha=0.5, lw=2,
570586 label=fr'$\alpha={α}, \beta={β}$')
571587 ax.set_ylim(0, 1)
588+ ax.set_xlabel('x')
589+ ax.set_ylabel('CDF')
572590plt.legend()
573591plt.show()
574592```
@@ -614,6 +632,8 @@ for α, β in zip(α_vals, β_vals):
614632 ax.plot(x_grid, u.pdf(x_grid),
615633 alpha=0.5, lw=2,
616634 label=fr'$\alpha={α}, \beta={β}$')
635+ ax.set_xlabel('x')
636+ ax.set_ylabel('PDF')
617637plt.legend()
618638plt.show()
619639```
@@ -626,6 +646,8 @@ for α, β in zip(α_vals, β_vals):
626646 alpha=0.5, lw=2,
627647 label=fr'$\alpha={α}, \beta={β}$')
628648 ax.set_ylim(0, 1)
649+ ax.set_xlabel('x')
650+ ax.set_ylabel('CDF')
629651plt.legend()
630652plt.show()
631653```
@@ -720,6 +742,8 @@ We can histogram the income distribution we just constructed as follows
720742x = df['income']
721743fig, ax = plt.subplots()
722744ax.hist(x, bins=5, density=True, histtype='bar')
745+ ax.set_xlabel('income')
746+ ax.set_ylabel('density')
723747plt.show()
724748```
725749
@@ -760,6 +784,8 @@ x_amazon = np.asarray(data)
760784``` {code-cell} ipython3
761785fig, ax = plt.subplots()
762786ax.hist(x_amazon, bins=20)
787+ ax.set_xlabel('monthly return (percent change)')
788+ ax.set_ylabel('density')
763789plt.show()
764790```
765791
@@ -774,6 +800,8 @@ KDE will generate a smooth curve that approximates the PDF.
774800``` {code-cell} ipython3
775801fig, ax = plt.subplots()
776802sns.kdeplot(x_amazon, ax=ax)
803+ ax.set_xlabel('monthly return (percent change)')
804+ ax.set_ylabel('KDE')
777805plt.show()
778806```
779807
@@ -784,6 +812,8 @@ fig, ax = plt.subplots()
784812sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.1, alpha=0.5, label="bw=0.1")
785813sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.5, alpha=0.5, label="bw=0.5")
786814sns.kdeplot(x_amazon, ax=ax, bw_adjust=1, alpha=0.5, label="bw=1")
815+ ax.set_xlabel('monthly return (percent change)')
816+ ax.set_ylabel('KDE')
787817plt.legend()
788818plt.show()
789819```
@@ -802,6 +832,8 @@ Yet another way to display an observed distribution is via a violin plot.
802832``` {code-cell} ipython3
803833fig, ax = plt.subplots()
804834ax.violinplot(x_amazon)
835+ ax.set_ylabel('monthly return (percent change)')
836+ ax.set_xlabel('KDE')
805837plt.show()
806838```
807839
@@ -822,6 +854,8 @@ x_apple = np.asarray(data)
822854``` {code-cell} ipython3
823855fig, ax = plt.subplots()
824856ax.violinplot([x_amazon, x_apple])
857+ ax.set_ylabel('monthly return (percent change)')
858+ ax.set_xlabel('KDE')
825859plt.show()
826860```
827861
@@ -855,6 +889,8 @@ x_grid = np.linspace(-50, 65, 200)
855889fig, ax = plt.subplots()
856890ax.plot(x_grid, u.pdf(x_grid))
857891ax.hist(x_amazon, density=True, bins=40)
892+ ax.set_xlabel('monthly return (percent change)')
893+ ax.set_ylabel('density')
858894plt.show()
859895```
860896
@@ -882,6 +918,8 @@ x_grid = np.linspace(-4, 4, 200)
882918fig, ax = plt.subplots()
883919ax.plot(x_grid, u.pdf(x_grid))
884920ax.hist(x_draws, density=True, bins=40)
921+ ax.set_xlabel('x')
922+ ax.set_ylabel('density')
885923plt.show()
886924```
887925
0 commit comments