8000 Cleanup polar_legend example. by anntzer · Pull Request #14954 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
Aug 8, 2019
Merged

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Aug 1, 2019

PR Summary

old: https://matplotlib.org/gallery/pie_and_polar_charts/polar_legend.html
new (local):
withpad
without the padding mentioned in the example:
withoutpad

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@ImportanceOfBeingErnest
Copy link
Member
ImportanceOfBeingErnest commented Aug 1, 2019

Instead of putting some heuristic borderaxespad=-2 in, one could also explain to people how to position the legend in general, like

angle = np.deg2rad(67.5)
ax.legend(loc="lower left",
          bbox_to_anchor=(.5 + np.cos(angle)/2, .5 + np.sin(angle)/2))

@anntzer
Copy link
Contributor Author
anntzer commented Aug 1, 2019

Isn't that going to need a heuristic too? (You don't know how far from the anchor you want to be... I think?)

@ImportanceOfBeingErnest
Copy link
Member

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.

@anntzer
Copy link
Contributor Author
anntzer commented Aug 1, 2019

Oooh, I see. Very cute, thanks, I learned something today :)
I pushed your version, feel free to directly push rewordings as necessary.

Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also suggesting to light the background and grid, so that this looks less muted, e.g. (without much tuning; other colors could be used as well):

after / before:

facecolor='#edf5c5'
grid_color='#9bc297'

grafik

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)
Copy link
Member

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

Suggested change
r = np.arange(0, 3.0, 0.01)
r = np.linspace(0, 3, 301)

Makes the spirals go up to the 0°/180° line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@anntzer
Copy link
Contributor Author
anntzer commented Aug 7, 2019

went for "palegoldenrod" as I have a mild preference for named colors and that's what a quick scan gave, but not particularly attached to it
new

Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you like named colors 😄

grafik

plt.rc('xtick', labelsize=15)
plt.rc('ytick', labelsize=15)
fig = plt.figure()
ax = fig.add_subplot(projection='polar', facecolor='palegoldenrod')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax.tick_params(grid_color='darkolivegreen')
ax.tick_params(grid_color='palegoldenrod')

@anntzer
Copy link
Contributor Author
anntzer commented Aug 7, 2019

thanks for the color suggestions :p

Copy link
Member
@QuLogic QuLogic left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed

@timhoffm timhoffm added this to the v3.2.0 milestone Aug 8, 2019
@timhoffm timhoffm merged commit 71a785d into matplotlib:master Aug 8, 2019
@anntzer anntzer deleted the polarlegend branch August 8, 2019 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0