|
4 | 4 | ==========
|
5 | 5 |
|
6 | 6 | Demo of a line plot on a polar axis.
|
| 7 | +
|
| 8 | +The second plot shows the same data, but with the radial axis starting at r=1 |
| 9 | +and the angular axis starting at 0 degrees and ending at 225 degrees. Setting |
| 10 | +the origin of the radial axis to 0 allows the radial ticks to be placed at the |
| 11 | +same location as the first plot. |
7 | 12 | """
|
8 | 13 | import matplotlib.pyplot as plt
|
9 | 14 | import numpy as np
|
10 | 15 |
|
11 | 16 | r = np.arange(0, 2, 0.01)
|
12 | 17 | theta = 2 * np.pi * r
|
13 | 18 |
|
14 |
| -fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) |
| 19 | +fig, axs = plt.subplots(2, 1, figsize=(5, 8), subplot_kw={'projection': 'polar'}, |
| 20 | + layout='constrained') |
| 21 | +ax = axs[0] |
15 | 22 | ax.plot(theta, r)
|
16 | 23 | ax.set_rmax(2)
|
17 |
| -ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks |
| 24 | +ax.set_rticks([0.5, 1, 1.5, 2]) # Fewer radial ticks |
18 | 25 | ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line
|
19 | 26 | ax.grid(True)
|
20 | 27 |
|
21 | 28 | ax.set_title("A line plot on a polar axis", va='bottom')
|
| 29 | + |
| 30 | +ax = axs[1] |
| 31 | +ax.plot(theta, r) |
| 32 | +ax.set_rmax(2) |
| 33 | +ax.set_rmin(1) # Change the radial axis to only go from 1 to 2 |
| 34 | +ax.set_rorigin(0) # Set the origin of the radial axis to 0 |
| 35 | +ax.set_thetamin(0) |
| 36 | +ax.set_thetamax(225) |
| 37 | +ax.set_rticks([1, 1.5, 2]) # Fewer radial ticks |
| 38 | +ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line |
| 39 | + |
| 40 | +ax.grid(True) |
| 41 | +ax.set_title("Same plot, but with reduced axis limits", va='bottom') |
22 | 42 | plt.show()
|
23 | 43 |
|
24 | 44 | # %%
|
|
32 | 52 | # - `matplotlib.projections.polar`
|
33 | 53 | # - `matplotlib.projections.polar.PolarAxes`
|
34 | 54 | # - `matplotlib.projections.polar.PolarAxes.set_rticks`
|
| 55 | +# - `matplotlib.projections.polar.PolarAxes.set_rmin` |
| 56 | +# - `matplotlib.projections.polar.PolarAxes.set_rorigin` |
35 | 57 | # - `matplotlib.projections.polar.PolarAxes.set_rmax`
|
36 | 58 | # - `matplotlib.projections.polar.PolarAxes.set_rlabel_position`
|
37 | 59 | #
|
|
0 commit comments