|
1 |
| -Vectorize ``hatch``, ``edgecolor``, ``linewidth`` and ``linestyle`` in *hist* methods |
2 |
| -------------------------------------------------------------------------------------- |
| 1 | +Vectorize ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle`` in *hist* methods |
| 2 | +---------------------------------------------------------------------------------------------------- |
3 | 3 |
|
4 |
| -The parameters ``hatch``, ``edgecolor``, ``linewidth`` and ``linestyle`` of the |
5 |
| -`~matplotlib.axes.Axes.hist` method are now vectorized. |
| 4 | +The parameters ``hatch``, ``edgecolor``, ``facecolor``, ``linewidth`` and ``linestyle`` |
| 5 | +of the `~matplotlib.axes.Axes.hist` method are now vectorized. |
6 | 6 | This means that you can pass in unique parameters for each histogram that is generated
|
7 | 7 | when the input *x* has multiple datasets.
|
8 |
| -Note that the ``facecolor`` parameter is not vectorized, but the required behavior can |
9 |
| -be achieved by passing a list of colors to the ``color`` parameter. |
| 8 | + |
10 | 9 |
|
11 | 10 | .. plot::
|
12 | 11 | :include-source: true
|
13 |
| - :alt: Three charts, identified as ax1, ax2 and ax3, show a stacking of three |
14 |
| - histograms representing Poisson distributions. The histograms in ax1, ax2, |
15 |
| - and ax3 are differentiated by linewidths, hatches and linestyles, |
16 |
| - respectively. In ax1, ax2 and ax3, each histogram is bordered by a different |
17 |
| - color. |
| 12 | + :alt: Four charts, each displaying stacked histograms of three Poisson |
| 13 | + distributions. Each chart differentiates the histograms using various |
| 14 | + parameters: ax1 uses different linewidths, ax2 uses different hatches, ax3 |
| 15 | + uses different edgecolors, and ax4 uses different facecolors. Edgecolors have |
| 16 | + ax1 and ax3 as well to accentuate the differences between the histograms. |
| 17 | + |
| 18 | + import matplotlib.pyplot as plt |
| 19 | + import numpy as np |
| 20 | + np.random.seed(19680801) |
18 | 21 |
|
19 |
| - import matplotlib.pyplot as plt |
20 |
| - import numpy as np |
21 |
| - np.random.seed(19680801) |
| 22 | + fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(9, 9)) |
22 | 23 |
|
23 |
| - fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(10,5)) |
| 24 | + data1 = np.random.poisson(5, 1000) |
| 25 | + data2 = np.random.poisson(7, 1000) |
| 26 | + data3 = np.random.poisson(10, 1000) |
24 | 27 |
|
25 |
| - data1 = np.random.poisson(5, 1000) |
26 |
| - data2 = np.random.poisson(7, 1000) |
27 |
| - data3 = np.random.poisson(10, 1000) |
| 28 | + labels = ["Data 1", "Data 2", "Data 3"] |
28 | 29 |
|
29 |
| - labels = ["Data 1", "Data 2", "Data 3"] |
| 30 | + ax1.hist([data1, data2, data3], bins=range(17), histtype="step", stacked=True, |
| 31 | + edgecolor=["red", "green", "blue"], linewidth=[1, 2, 3]) |
| 32 | + ax1.set_title("Different linewidths") |
| 33 | + ax1.legend(labels) |
30 | 34 |
|
31 |
| - ax1.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
32 |
| - edgecolor=["red", "green", "blue"], linewidth=[1, 1.5, 2]) |
33 |
| - ax1.set_title("Different linewidths") |
34 |
| - ax1.legend(labels, prop={"size": 8}) |
| 35 | + ax2.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
| 36 | + hatch=["/", ".", "*"]) |
| 37 | + ax2.set_title("Different hatch patterns") |
| 38 | + ax2.legend(labels) |
35 | 39 |
|
36 |
| - ax2.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
37 |
| - edgecolor=["red", "green", "blue"], hatch=["/", ".", "*"]) |
38 |
| - ax2.set_title("Different hatch patterns") |
39 |
| - ax2.legend(labels, prop={"size": 8}) |
| 40 | + ax3.hist([data1, data2, data3], bins=range(17), histtype="bar", fill=False, |
| 41 | + edgecolor=["red", "green", "blue"], linestyle=["--", "-.", ":"]) |
| 42 | + ax3.set_title("Different linestyles") |
| 43 | + ax3.legend(labels) |
40 | 44 |
|
41 |
| - ax3.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
42 |
| - edgecolor=["red", "green", "blue"], linestyle=["--", "-.", ":"]) |
43 |
| - ax3.set_title("Different linestyles") |
44 |
| - ax3.legend(labels, prop={"size": 8}) |
| 45 | + ax4.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
| 46 | + facecolor=["red", "green", "blue"]) |
| 47 | + ax4.set_title("Different facecolors") |
| 48 | + ax4.legend(labels) |
45 | 49 |
|
46 |
| - plt.show() |
| 50 | + plt.show() |
0 commit comments