8000 Cleanup polar_legend example. · matplotlib/matplotlib@db1b7b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit db1b7b2

Browse files
committed
Cleanup polar_legend example.
1 parent 9affee4 commit db1b7b2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/pie_and_polar_charts/polar_legend.py

Lines changed: 12 additions & 12 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)
16-
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')
12+
fig = plt.figure()
13+
ax = fig.add_subplot(projection='polar', facecolor='#d5de9c')
2114

2215
r = np.arange(0, 3.0, 0.01)
2316
theta = 2 * np.pi * r
24-
ax.plot(theta, r, color='#ee8d18', lw=3, label='a l 9235 ine')
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='darkolivegreen')
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