Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f93187

Browse files
committed
Made a more detailed gallery example
Fix Docs
1 parent bdfc2e7 commit 0f93187

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

galleries/examples/statistics/histogram_multihist.py

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
select these parameters:
1616
http://docs.astropy.org/en/stable/visualization/histogram.html
1717
"""
18-
18+
# %%
1919
import matplotlib.pyplot as plt
2020
import numpy as np
2121

@@ -27,29 +27,77 @@
2727
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
2828

2929
colors = ['red', 'tan', 'lime']
30-
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors,
31-
label=colors, hatch=['o', '*', '.'],
32-
edgecolor=['black', 'red', 'blue'], linewidth=[1, 2, 3])
30+
ax0.hist(x, n_bins, density=True, histtype="bar", color=colors, label=colors)
3331
ax0.legend(prop={'size': 10})
3432
ax0.set_title('bars with legend')
3533

36-
ax1.hist(
37-
x, n_bins, density=True, histtype="bar", stacked=True,
38-
edgecolor=["black", "yellow", "blue"])
34+
ax1.hist(x, n_bins, density=True, histtype="bar", stacked=True)
3935
ax1.set_title('stacked bar')
4036

41-
ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False,
42-
linewidth=[1, 2, 3])
37+
ax2.hist(x, n_bins, histtype="step", stacked=True, fill=False)
4338
ax2.set_title('stack step (unfilled)')
4439

4540
# Make a multiple-histogram of data-sets with different length.
4641
x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
47-
ax3.hist(x_multi, n_bins, histtype='bar', hatch=['\\', '/', '-'])
42+
ax3.hist(x_multi, n_bins, histtype="bar")
4843
ax3.set_title('different sample sizes')
4944

5045
fig.tight_layout()
5146
plt.show()
5247

48+
# %%
49+
# Setting properties for each sample set
50+
# ------------
51+
#
52+
# Plotting a bar chart with sample sets differentiated using:
53+
#
54+
# * edgecolors
55+
# * hatches
56+
# * linewidths
57+
# * linestyles
58+
#
59+
# Also, these parameters can be specified for all types of
60+
# histograms (stacked, step, etc.) and not just for the *bar*
61+
# type histogram as shown in the example.
62+
63+
hatches = ["-", "o", "x"]
64+
linewidths = [1, 2, 3]
65+
edgecolors = ["green", "red", "blue"]
66+
linestyles = ["-", ":", "--"]
67+
68+
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)
69+
70+
ax0.hist(
71+
x, n_bins, density=True, fill=False, histtype="bar",
72+
edgecolor=edgecolors, label=edgecolors
73+
)
74+
ax0.legend(prop={"size": 10})
75+
ax0.set_title("Bars with Edgecolors")
76+
77+
ax1.hist(
78+
x, n_bins, density=True, histtype="bar",
79+
hatch=hatches, label=hatches
80+
)
81+
ax1.legend(prop={"size": 10})
82+
ax1.set_title("Bars with Hatches")
83+
84+
ax2.hist(
85+
x, n_bins, density=True, fill=False, histtype="bar",
86+
linewidth=linewidths, edgecolor=edgecolors, label=linewidths
87+
)
88+
ax2.legend(prop={"size": 10})
89+
ax2.set_title("Bars with Linewidths")
90+
91+
ax3.hist(
92+
x, n_bins, density=True, fill=False, histtype="bar",
93+
linestyle=linestyles, edgecolor=edgecolors, label=linestyles
94+
)
95+
ax3.legend(prop={"size": 10})
96+
ax3.set_title("Bars with Linestyles")
97+
98+
fig.tight_layout()
99+
plt.show()
100+
53101
# %%
54102
#
55103
# .. admonition:: References

0 commit comments

Comments
 (0)