|
21 | 21 | #
|
22 | 22 | # To generate a 1D histogram we only need a single vector of numbers. For a 2D
|
23 | 23 | # histogram we'll need a second vector. We'll generate both below, and show
|
24 |
| -# the histogram for each vector |
| 24 | +# the histogram for each vector. |
25 | 25 |
|
26 | 26 | N_points = 100000
|
27 | 27 | n_bins = 20
|
|
44 | 44 | # The histogram method returns (among other things) a `patches` object. This
|
45 | 45 | # gives us access to the properties of the objects drawn. Using this, we can
|
46 | 46 | # edit the histogram to our liking. Let's change the color of each bar
|
47 |
| -# based on its y value |
| 47 | +# based on its y value. |
48 | 48 |
|
49 | 49 | fig, axs = plt.subplots(1, 2, figsize=(10, 5), tight_layout=True)
|
50 | 50 |
|
|
62 | 62 | color = plt.cm.viridis(norm(thisfrac))
|
63 | 63 | thispatch.set_facecolor(color)
|
64 | 64 |
|
65 |
| -# We can also normalize our inputs by the total number of counts. |
| 65 | +# We can also normalize our inputs by the total number of counts |
66 | 66 | axs[1].hist(x, bins=n_bins, normed=True)
|
67 | 67 |
|
68 | 68 | # Now we format the y-axis to display percentage
|
|
79 | 79 | fig, ax = plt.subplots(tight_layout=True)
|
80 | 80 | hist = ax.hist2d(x, y)
|
81 | 81 |
|
| 82 | + |
82 | 83 | ###############################################################################
|
83 | 84 | # Customizing your histogram
|
84 | 85 | # --------------------------
|
85 | 86 | #
|
86 | 87 | # Customizing a 2D histogram is similar to the 1D case, you can control
|
87 |
| -# visual components such as the bin size or color normalization |
| 88 | +# visual components such as the bin size or color normalization. |
88 | 89 |
|
89 | 90 | fig, axs = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True,
|
90 | 91 | tight_layout=True)
|
|
0 commit comments