From 8f4ce304a9bc443e0f8f5ab43a19d9a007a2d022 Mon Sep 17 00:00:00 2001 From: Emlyn Price Date: Tue, 1 Oct 2019 21:23:14 +0100 Subject: [PATCH 1/5] Add 'step' to histtype demo Add the step histogram type to the histtype demo --- examples/statistics/histogram_histtypes.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/statistics/histogram_histtypes.py b/examples/statistics/histogram_histtypes.py index 9ea875617f2e..bda7f0e78501 100644 --- a/examples/statistics/histogram_histtypes.py +++ b/examples/statistics/histogram_histtypes.py @@ -21,15 +21,18 @@ sigma = 25 x = np.random.normal(mu, sigma, size=100) -fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4)) +fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 4)) ax0.hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) ax0.set_title('stepfilled') +ax1.hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) +ax1.set_title('step') + # Create a histogram by providing the bin edges (unequally spaced). bins = [100, 150, 180, 195, 205, 220, 250, 300] -ax1.hist(x, bins, density=True, histtype='bar', rwidth=0.8) -ax1.set_title('unequal bins') +ax2.hist(x, bins, density=True, histtype='bar', rwidth=0.8) +ax2.set_title('bar, unequal bins') fig.tight_layout() plt.show() From 40e1c34ba4bf2e7454f48118fd379e8cfe19e447 Mon Sep 17 00:00:00 2001 From: Emlyn Price Date: Tue, 1 Oct 2019 21:48:22 +0100 Subject: [PATCH 2/5] Update histtype demo to show barstacked type --- examples/statistics/histogram_histtypes.py | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/statistics/histogram_histtypes.py b/examples/statistics/histogram_histtypes.py index bda7f0e78501..392da14b28fe 100644 --- a/examples/statistics/histogram_histtypes.py +++ b/examples/statistics/histogram_histtypes.py @@ -17,22 +17,33 @@ np.random.seed(19680801) -mu = 200 -sigma = 25 -x = np.random.normal(mu, sigma, size=100) +mu_x = 200 +sigma_x = 25 +x = np.random.normal(mu_x, sigma_x, size=100) -fig, (ax0, ax1, ax2) = plt.subplots(ncols=3, figsize=(8, 4)) +mu_w = 200 +sigma_w = 10 +w = np.random.normal(mu_w, sigma_w, size=100) -ax0.hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) -ax0.set_title('stepfilled') +fig, ax = plt.subplots(nrows=2, ncols=2) -ax1.hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) -ax1.set_title('step') +ax[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) +ax[0, 0].set_title('stepfilled') + +ax[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) +ax[0, 1].set_title('step') + +# Plot two histograms to demonstrate the barstacked histtype +ax[1, 0].hist(x, density=True, histtype='barstacked', rwidth=0.8) +ax[1, 0].hist(w, density=True, histtype='barstacked', rwidth=0.8) +ax[1, 0].set_title('barstacked') # Create a histogram by providing the bin edges (unequally spaced). bins = [100, 150, 180, 195, 205, 220, 250, 300] -ax2.hist(x, bins, density=True, histtype='bar', rwidth=0.8) -ax2.set_title('bar, unequal bins') +ax[1, 1].hist(x, bins, density=True, histtype='bar', rwidth=0.8) +ax[1, 1].set_title('bar, unequal bins') + + fig.tight_layout() plt.show() From b2b81c373f440260f864e60f465b1b82ddea4a20 Mon Sep 17 00:00:00 2001 From: Emlyn Price Date: Tue, 1 Oct 2019 21:53:49 +0100 Subject: [PATCH 3/5] Change ax to axs --- examples/statistics/histogram_histtypes.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/statistics/histogram_histtypes.py b/examples/statistics/histogram_histtypes.py index 392da14b28fe..6535b81d0207 100644 --- a/examples/statistics/histogram_histtypes.py +++ b/examples/statistics/histogram_histtypes.py @@ -25,25 +25,23 @@ sigma_w = 10 w = np.random.normal(mu_w, sigma_w, size=100) -fig, ax = plt.subplots(nrows=2, ncols=2) +fig, axs = plt.subplots(nrows=2, ncols=2) -ax[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) -ax[0, 0].set_title('stepfilled') +axs[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) +axs[0, 0].set_title('stepfilled') -ax[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) -ax[0, 1].set_title('step') +axs[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) +axs[0, 1].set_title('step') # Plot two histograms to demonstrate the barstacked histtype -ax[1, 0].hist(x, density=True, histtype='barstacked', rwidth=0.8) -ax[1, 0].hist(w, density=True, histtype='barstacked', rwidth=0.8) -ax[1, 0].set_title('barstacked') +axs[1, 0].hist(x, density=True, histtype='barstacked', rwidth=0.8) +axs[1, 0].hist(w, density=True, histtype='barstacked', rwidth=0.8) +axs[1, 0].set_title('barstacked') # Create a histogram by providing the bin edges (unequally spaced). bins = [100, 150, 180, 195, 205, 220, 250, 300] -ax[1, 1].hist(x, bins, density=True, histtype='bar', rwidth=0.8) -ax[1, 1].set_title('bar, unequal bins') - - +axs[1, 1].hist(x, bins, density=True, histtype='bar', rwidth=0.8) +axs[1, 1].set_title('bar, unequal bins') fig.tight_layout() plt.show() From bb94b5936c927060697199d996e52ae8a87c43c8 Mon Sep 17 00:00:00 2001 From: Emlyn Price Date: Thu, 3 Oct 2019 20:02:23 +0100 Subject: [PATCH 4/5] Fix long line --- examples/statistics/histogram_histtypes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/statistics/histogram_histtypes.py b/examples/statistics/histogram_histtypes.py index 6535b81d0207..407127534163 100644 --- a/examples/statistics/histogram_histtypes.py +++ b/examples/statistics/histogram_histtypes.py @@ -27,10 +27,12 @@ fig, axs = plt.subplots(nrows=2, ncols=2) -axs[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g', alpha=0.75) +axs[0, 0].hist(x, 20, density=True, histtype='stepfilled', facecolor='g', + alpha=0.75) axs[0, 0].set_title('stepfilled') -axs[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g', alpha=0.75) +axs[0, 1].hist(x, 20, density=True, histtype='step', facecolor='g', + alpha=0.75) axs[0, 1].set_title('step') # Plot two histograms to demonstrate the barstacked histtype From a8ab65826a2183f3209c1057e18bd66b28462c62 Mon Sep 17 00:00:00 2001 From: Emlyn Price Date: Thu, 3 Oct 2019 23:29:31 +0100 Subject: [PATCH 5/5] Add note of the examples at the top of the page --- examples/statistics/histogram_histtypes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/statistics/histogram_histtypes.py b/examples/statistics/histogram_histtypes.py index 407127534163..2ec4fc9e1836 100644 --- a/examples/statistics/histogram_histtypes.py +++ b/examples/statistics/histogram_histtypes.py @@ -4,7 +4,9 @@ ================================================================ * Histogram with step curve that has a color fill. +* Histogram with step curve with no fill. * Histogram with custom and unequal bin widths. +* Two histograms with stacked bars. Selecting different bin counts and sizes can significantly affect the shape of a histogram. The Astropy docs have a great section on how to @@ -35,7 +37,6 @@ alpha=0.75) axs[0, 1].set_title('step') -# Plot two histograms to demonstrate the barstacked histtype axs[1, 0].hist(x, density=True, histtype='barstacked', rwidth=0.8) axs[1, 0].hist(w, density=True, histtype='barstacked', rwidth=0.8) axs[1, 0].set_title('barstacked')