Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f8a459

Browse filesBrowse files
rcomerjklymak
andauthored
Backport PR #30180: DOC: expand polar example (#30190)
Co-authored-by: Jody Klymak <jklymak@gmail.com>
2 parents 34cca89 + 3950d99 commit 7f8a459
Copy full SHA for 7f8a459

File tree

Expand file treeCollapse file tree

1 file changed

+24
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-2
lines changed

‎galleries/examples/pie_and_polar_charts/polar_demo.py

Copy file name to clipboardExpand all lines: galleries/examples/pie_and_polar_charts/polar_demo.py
+24-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.