|
9 | 9 | import matplotlib.pyplot as plt
|
10 | 10 | import numpy as np
|
11 | 11 |
|
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") |
16 | 14 |
|
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) |
23 | 16 | 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)) |
27 | 27 |
|
28 | 28 | plt.show()
|
29 | 29 |
|
|
0 commit comments