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

Skip to content

Commit 49085a9

Browse files
committed
DOC: clarify boxplot color demo
1 parent 39ffd6c commit 49085a9

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
"""Box plots with custom fill colors."""
1+
"""Box plots with custom fill colors.
2+
3+
This plot illustrates how to create two types of boxplots
4+
(rectangular and notched), and how to fill them with custom
5+
colors by accessing the properties of the artists of the
6+
boxplots. Additionally, the ``labels`` parameter is used to
7+
provide x-tick labels for each sample.
8+
"""
29

310
import matplotlib.pyplot as plt
411
import numpy as np
512

613
# Random test data
714
np.random.seed(123)
8-
all_data = [np.random.normal(0, std, 100) for std in range(1, 4)]
15+
all_data = [np.random.normal(0, std, size=(100, 4)) for std in range(1, 4)]
16+
labels = ['x1', 'x2', 'x3']
917

1018
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5))
1119

1220
# rectangular box plot
1321
bplot1 = axes[0].boxplot(all_data,
14-
vert=True, # vertical box aligmnent
15-
patch_artist=True) # fill with color
22+
vert=True, # vertical box aligmnent
23+
patch_artist=True, # fill with color
24+
labels=labels) # will be used to label x-ticks
1625

1726
# notch shape box plot
1827
bplot2 = axes[1].boxplot(all_data,
1928
notch=True, # notch shape
20-
vert=True, # vertical box aligmnent
21-
patch_artist=True) # fill with color
29+
vert=True, # vertical box aligmnent
30+
patch_artist=True, # fill with color
31+
labels=labels) # will be used to label x-ticks
2232

2333
# fill with colors
2434
colors = ['pink', 'lightblue', 'lightgreen']
@@ -29,12 +39,7 @@
2939
# adding horizontal grid lines
3040
for ax in axes:
3141
ax.yaxis.grid(True)
32-
ax.set_xticks([y + 1 for y in range(len(all_data))], )
33-
ax.set_xlabel('xlabel')
34-
ax.set_ylabel('ylabel')
35-
36-
# add x-tick labels
37-
plt.setp(axes, xticks=[y + 1 for y in range(len(all_data))],
38-
xticklabels=['x1', 'x2', 'x3', 'x4'])
42+
ax.set_xlabel('Three Separate Samples')
43+
ax.set_ylabel('Observed values')
3944

4045
plt.show()

0 commit comments

Comments
 (0)