|
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 distributions. Each chart differentiates the histograms using various parameters: ax1 uses different linewidths, ax2 uses different hatches, ax3 uses different edgecolors, and ax4 uses different facecolors. Edgecolors have ax1 and ax3 as well to accentuate the differences between the histograms. |
18 | 13 |
|
19 | 14 | import matplotlib.pyplot as plt
|
20 | 15 | import numpy as np
|
21 | 16 | np.random.seed(19680801)
|
22 | 17 |
|
23 |
| - fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(10,5)) |
| 18 | + fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(9, 9)) |
24 | 19 |
|
25 | 20 | data1 = np.random.poisson(5, 1000)
|
26 | 21 | data2 = np.random.poisson(7, 1000)
|
27 | 22 | data3 = np.random.poisson(10, 1000)
|
28 | 23 |
|
29 | 24 | labels = ["Data 1", "Data 2", "Data 3"]
|
30 | 25 |
|
31 |
| - ax1.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
32 |
| - edgecolor=["red", "green", "blue"], linewidth=[1, 1.5, 2]) |
| 26 | + ax1.hist([data1, data2, data3], bins=range(17), histtype="step", stacked=True, |
| 27 | + edgecolor=["red", "green", "blue"], linewidth=[1, 2, 3]) |
33 | 28 | ax1.set_title("Different linewidths")
|
34 |
| - ax1.legend(labels, prop={"size": 8}) |
| 29 | + ax1.legend(labels) |
35 | 30 |
|
36 | 31 | ax2.hist([data1, data2, data3], bins=range(17), histtype="barstacked",
|
37 |
| - edgecolor=["red", "green", "blue"], hatch=["/", ".", "*"]) |
| 32 | + hatch=["/", ".", "*"]) |
38 | 33 | ax2.set_title("Different hatch patterns")
|
39 |
| - ax2.legend(labels, prop={"size": 8}) |
| 34 | + ax2.legend(labels) |
40 | 35 |
|
41 |
| - ax3.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
| 36 | + ax3.hist([data1, data2, data3], bins=range(17), histtype="bar", fill=False, |
42 | 37 | edgecolor=["red", "green", "blue"], linestyle=["--", "-.", ":"])
|
43 | 38 | ax3.set_title("Different linestyles")
|
44 |
| - ax3.legend(labels, prop={"size": 8}) |
| 39 | + ax3.legend(labels) |
| 40 | + |
| 41 | + ax4.hist([data1, data2, data3], bins=range(17), histtype="barstacked", |
| 42 | + facecolor=["red", "green", "blue"]) |
| 43 | + ax4.set_title("Different facecolors") |
| 44 | + ax4.legend(labels) |
45 | 45 |
|
46 | 46 | plt.show()
|
0 commit comments