Skip to content

Commit 707c5dd

Browse files
committed
add x y label
1 parent d641f7f commit 707c5dd

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

lectures/prob_dist.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ S = np.arange(1, n+1)
124124
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
125125
ax.vlines(S, 0, u.pmf(S), lw=0.2)
126126
ax.set_xticks(S)
127+
ax.set_xlabel('S')
128+
ax.set_ylabel('PMF')
127129
plt.show()
128130
```
129131

@@ -136,6 +138,8 @@ S = np.arange(1, n+1)
136138
ax.step(S, u.cdf(S))
137139
ax.vlines(S, 0, u.cdf(S), lw=0.2)
138140
ax.set_xticks(S)
141+
ax.set_xlabel('S')
142+
ax.set_ylabel('CDF')
139143
plt.show()
140144
```
141145

@@ -232,6 +236,8 @@ S = np.arange(1, n+1)
232236
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
233237
ax.vlines(S, 0, u.pmf(S), lw=0.2)
234238
ax.set_xticks(S)
239+
ax.set_xlabel('S')
240+
ax.set_ylabel('PMF')
235241
plt.show()
236242
```
237243

@@ -244,6 +250,8 @@ S = np.arange(1, n+1)
244250
ax.step(S, u.cdf(S))
245251
ax.vlines(S, 0, u.cdf(S), lw=0.2)
246252
ax.set_xticks(S)
253+
ax.set_xlabel('S')
254+
ax.set_ylabel('CDF')
247255
plt.show()
248256
```
249257

@@ -267,6 +275,8 @@ u_sum = np.cumsum(u.pmf(S))
267275
ax.step(S, u_sum)
268276
ax.vlines(S, 0, u_sum, lw=0.2)
269277
ax.set_xticks(S)
278+
ax.set_xlabel('S')
279+
ax.set_ylabel('CDF')
270280
plt.show()
271281
```
272282

@@ -306,6 +316,8 @@ S = np.arange(1, n+1)
306316
ax.plot(S, u.pmf(S), linestyle='', marker='o', alpha=0.8, ms=4)
307317
ax.vlines(S, 0, u.pmf(S), lw=0.2)
308318
ax.set_xticks(S)
319+
ax.set_xlabel('S')
320+
ax.set_ylabel('PMF')
309321
plt.show()
310322
```
311323

@@ -378,7 +390,8 @@ for μ, σ in zip(μ_vals, σ_vals):
378390
ax.plot(x_grid, u.pdf(x_grid),
379391
alpha=0.5, lw=2,
380392
label=f'$\mu={μ}, \sigma={σ}$')
381-
393+
ax.set_xlabel('x')
394+
ax.set_ylabel('PDF')
382395
plt.legend()
383396
plt.show()
384397
```
@@ -394,6 +407,8 @@ for μ, σ in zip(μ_vals, σ_vals):
394407
alpha=0.5, lw=2,
395408
label=f'$\mu={μ}, \sigma={σ}$')
396409
ax.set_ylim(0, 1)
410+
ax.set_xlabel('x')
411+
ax.set_ylabel('CDF')
397412
plt.legend()
398413
plt.show()
399414
```
@@ -438,7 +453,8 @@ for μ, σ in zip(μ_vals, σ_vals):
438453
ax.plot(x_grid, u.pdf(x_grid),
439454
alpha=0.5, lw=2,
440455
label=f'$\mu={μ}, \sigma={σ}$')
441-
456+
ax.set_xlabel('x')
457+
ax.set_ylabel('PDF')
442458
plt.legend()
443459
plt.show()
444460
```
@@ -453,6 +469,8 @@ for σ in σ_vals:
453469
label=f'$\mu={μ}, \sigma={σ}$')
454470
ax.set_ylim(0, 1)
455471
ax.set_xlim(0, 3)
472+
ax.set_xlabel('x')
473+
ax.set_ylabel('CDF')
456474
plt.legend()
457475
plt.show()
458476
```
@@ -492,6 +510,8 @@ for λ in λ_vals:
492510
ax.plot(x_grid, u.pdf(x_grid),
493511
alpha=0.5, lw=2,
494512
label=f'$\lambda={λ}$')
513+
ax.set_xlabel('x')
514+
ax.set_ylabel('PDF')
495515
plt.legend()
496516
plt.show()
497517
```
@@ -504,6 +524,8 @@ for λ in λ_vals:
504524
alpha=0.5, lw=2,
505525
label=f'$\lambda={λ}$')
506526
ax.set_ylim(0, 1)
527+
ax.set_xlabel('x')
528+
ax.set_ylabel('CDF')
507529
plt.legend()
508530
plt.show()
509531
```
@@ -549,6 +571,8 @@ for α, β in zip(α_vals, β_vals):
549571
ax.plot(x_grid, u.pdf(x_grid),
550572
alpha=0.5, lw=2,
551573
label=fr'$\alpha={α}, \beta={β}$')
574+
ax.set_xlabel('x')
575+
ax.set_ylabel('PDF')
552576
plt.legend()
553577
plt.show()
554578
```
@@ -561,6 +585,8 @@ for α, β in zip(α_vals, β_vals):
561585
alpha=0.5, lw=2,
562586
label=fr'$\alpha={α}, \beta={β}$')
563587
ax.set_ylim(0, 1)
588+
ax.set_xlabel('x')
589+
ax.set_ylabel('CDF')
564590
plt.legend()
565591
plt.show()
566592
```
@@ -606,6 +632,8 @@ for α, β in zip(α_vals, β_vals):
606632
ax.plot(x_grid, u.pdf(x_grid),
607633
alpha=0.5, lw=2,
608634
label=fr'$\alpha={α}, \beta={β}$')
635+
ax.set_xlabel('x')
636+
ax.set_ylabel('PDF')
609637
plt.legend()
610638
plt.show()
611639
```
@@ -618,6 +646,8 @@ for α, β in zip(α_vals, β_vals):
618646
alpha=0.5, lw=2,
619647
label=fr'$\alpha={α}, \beta={β}$')
620648
ax.set_ylim(0, 1)
649+
ax.set_xlabel('x')
650+
ax.set_ylabel('CDF')
621651
plt.legend()
622652
plt.show()
623653
```
@@ -712,6 +742,8 @@ We can histogram the income distribution we just constructed as follows
712742
x = df['income']
713743
fig, ax = plt.subplots()
714744
ax.hist(x, bins=5, density=True, histtype='bar')
745+
ax.set_xlabel('Income')
746+
ax.set_ylabel('Density')
715747
plt.show()
716748
```
717749

@@ -752,6 +784,8 @@ x_amazon = np.asarray(data)
752784
```{code-cell} ipython3
753785
fig, ax = plt.subplots()
754786
ax.hist(x_amazon, bins=20)
787+
ax.set_xlabel('Monthly Return (Percent Change)')
788+
ax.set_ylabel('Density')
755789
plt.show()
756790
```
757791

@@ -766,6 +800,8 @@ KDE will generate a smooth curve that approximates the PDF.
766800
```{code-cell} ipython3
767801
fig, ax = plt.subplots()
768802
sns.kdeplot(x_amazon, ax=ax)
803+
ax.set_xlabel('Monthly Return (Percent Change)')
804+
ax.set_ylabel('KDE')
769805
plt.show()
770806
```
771807

@@ -776,6 +812,8 @@ fig, ax = plt.subplots()
776812
sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.1, alpha=0.5, label="bw=0.1")
777813
sns.kdeplot(x_amazon, ax=ax, bw_adjust=0.5, alpha=0.5, label="bw=0.5")
778814
sns.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')
779817
plt.legend()
780818
plt.show()
781819
```
@@ -794,6 +832,8 @@ Yet another way to display an observed distribution is via a violin plot.
794832
```{code-cell} ipython3
795833
fig, ax = plt.subplots()
796834
ax.violinplot(x_amazon)
835+
ax.set_ylabel('Monthly Return (Percent Change)')
836+
ax.set_xlabel('KDE')
797837
plt.show()
798838
```
799839

@@ -814,6 +854,8 @@ x_apple = np.asarray(data)
814854
```{code-cell} ipython3
815855
fig, ax = plt.subplots()
816856
ax.violinplot([x_amazon, x_apple])
857+
ax.set_ylabel('Monthly Return (Percent Change)')
858+
ax.set_xlabel('KDE')
817859
plt.show()
818860
```
819861

@@ -847,6 +889,8 @@ x_grid = np.linspace(-50, 65, 200)
847889
fig, ax = plt.subplots()
848890
ax.plot(x_grid, u.pdf(x_grid))
849891
ax.hist(x_amazon, density=True, bins=40)
892+
ax.set_xlabel('Monthly Return (Percent Change)')
893+
ax.set_ylabel('Density')
850894
plt.show()
851895
```
852896

@@ -874,6 +918,8 @@ x_grid = np.linspace(-4, 4, 200)
874918
fig, ax = plt.subplots()
875919
ax.plot(x_grid, u.pdf(x_grid))
876920
ax.hist(x_draws, density=True, bins=40)
921+
ax.set_xlabel('x')
922+
ax.set_ylabel('Density')
877923
plt.show()
878924
```
879925

0 commit comments

Comments
 (0)