Skip to content

Commit 33a0d07

Browse files
jklymakrcomer
andauthored
DOC: expand polar example (matplotlib#30180)
* DOC: expand polar example * DOC: expand polar example * Apply suggestions from code review Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --------- Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent e325459 commit 33a0d07

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

galleries/examples/pie_and_polar_charts/polar_demo.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,41 @@
44
==========
55
66
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.
712
"""
813
import matplotlib.pyplot as plt
914
import numpy as np
1015

1116
r = np.arange(0, 2, 0.01)
1217
theta = 2 * np.pi * r
1318

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]
1522
ax.plot(theta, r)
1623
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
1825
ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line
1926
ax.grid(True)
2027

2128
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')
2242
plt.show()
2343

2444
# %%
@@ -32,6 +52,8 @@
3252
# - `matplotlib.projections.polar`
3353
# - `matplotlib.projections.polar.PolarAxes`
3454
# - `matplotlib.projections.polar.PolarAxes.set_rticks`
55+
# - `matplotlib.projections.polar.PolarAxes.set_rmin`
56+
# - `matplotlib.projections.polar.PolarAxes.set_rorigin`
3557
# - `matplotlib.projections.polar.PolarAxes.set_rmax`
3658
# - `matplotlib.projections.polar.PolarAxes.set_rlabel_position`
3759
#

0 commit comments

Comments
 (0)