-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cleanup polar_legend example. #14954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Instead of putting some heuristic
|
Isn't that going to need a heuristic too? (You don't know how far from the anchor you want to be... I think?) |
The code above will of course only look good within the first quadrant (0 <= angle <= 90) and the legend may still overlap the ticklabels, e.g. if angle=45. But it's more transparent and doesn't depend on the figure size. |
Oooh, I see. Very cute, thanks, I learned something today :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], | ||
projection='polar', facecolor='#d5de9c') | ||
fig = plt.figure() | ||
ax = fig.add_subplot(projection='polar', facecolor='#d5de9c') | ||
|
||
r = np.arange(0, 3.0, 0.01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're at it, it would be nice to replace this with
r = np.arange(0, 3.0, 0.01) | |
r = np.linspace(0, 3, 301) |
Makes the spirals go up to the 0°/180° line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plt.rc('xtick', labelsize=15) | ||
plt.rc('ytick', labelsize=15) | ||
fig = plt.figure() | ||
ax = fig.add_subplot(projection='polar', facecolor='palegoldenrod') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ax = fig.add_subplot(projection='polar', facecolor='palegoldenrod') | |
ax = fig.add_subplot(projection='polar', facecolor='lightgoldenrodyellow') |
ax.legend() | ||
ax.plot(theta, r, color='tab:orange', lw=3, label='a line') | ||
ax.plot(0.5 * theta, r, color='tab:blue', ls='--', lw=3, label='another line') | ||
ax.tick_params(grid_color='darkolivegreen') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ax.tick_params(grid_color='darkolivegreen') | |
ax.tick_params(grid_color='palegoldenrod') |
thanks for the color suggestions :p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One typo.
ax.tick_params(grid_color="palegoldenrod") | ||
# For polar axes, it may be useful to move the legend slightly away from the | ||
# axes center, to avoid overlap between the legend and the axes. The following | ||
# snippet places the legend"s lower left corner just outside of the polar axes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# snippet places the legend"s lower left corner just outside of the polar axes | |
# snippet places the legend's lower left corner just outside of the polar axes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed
PR Summary
old: https://matplotlib.org/gallery/pie_and_polar_charts/polar_legend.html


new (local):
without the padding mentioned in the example:
PR Checklist