8000 Merge pull request #14954 from anntzer/polarlegend · matplotlib/matplotlib@71a785d · GitHub
[go: up one dir, main page]

Skip to content

Commit 71a785d

Browse files
authored
Merge pull request #14954 from anntzer/polarlegend
Cleanup polar_legend example.
2 parents 3253ba1 + fdad188 commit 71a785d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

examples/pie_and_polar_charts/polar_legend.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
import matplotlib.pyplot as plt
1010
import numpy as np
1111

12-
# radar green, solid grid lines
13-
plt.rc('grid', color='#316931', linewidth=1, linestyle='-')
14-
plt.rc('xtick', labelsize=15)
15-
plt.rc('ytick', labelsize=15)
12+
fig = plt.figure()
13+
ax = fig.add_subplot(projection="polar", facecolor="lightgoldenrodyellow")
1614

17-
# force square figure and square axes looks better for polar, IMO
18-
fig = plt.figure(figsize=(8, 8))
19-
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8],
20-
projection='polar', facecolor='#d5de9c')
21-
22-
r = np.arange(0, 3.0, 0.01)
15+
r = np.linspace(0, 3, 301)
2316
theta = 2 * np.pi * r
24-
ax.plot(theta, r, color='#ee8d18', lw=3, label='a line')
25-
ax.plot(0.5 * theta, r, color='blue', ls='--', lw=3, label='another line')
26-
ax.legend()
17+
ax.plot(theta, r, color="tab:orange", lw=3, label="a line")
18+
ax.plot(0.5 * theta, r, color="tab:blue", ls="--", lw=3, label="another line")
19+
ax.tick_params(grid_color="palegoldenrod")
20+
# For polar axes, it may be useful to move the legend slightly away from the
21+
# axes center, to avoid overlap between the legend and the axes. The following
22+
# snippet places the legend's lower left corner just outside of the polar axes
23+
# at an angle of 67.5 degrees in polar coordinates.
24+
angle = np.deg2rad(67.5)
25+
ax.legend(loc="lower left",
26+
bbox_to_anchor=(.5 + np.cos(angle)/2, .5 + np.sin(angle)/2))
2727

2828
plt.show()
2929

0 commit comments

Comments
 (0)
0