Skip to content

set_rgrids() in a polar plot cannot set ticklabel size #17463

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

Open
AgilentGCMS opened this issue May 20, 2020 · 6 comments
Open

set_rgrids() in a polar plot cannot set ticklabel size #17463

AgilentGCMS opened this issue May 20, 2020 · 6 comments

Comments

@AgilentGCMS
Copy link

Bug report

In a polar plot, I want to set the sizes of the r and theta ticklabels. While setting the theta ticklabel size works with the method set_thetagrids, setting the r ticklabel size with set_rgrids does not work.

As an aside, I find it confusing that some functions for setting theta parameters require arguments in radians (e.g., set_thetalim), while others require arguments in degrees (e.g., set_thetagrids).

Code snippet

from matplotlib import pyplot as plt
import numpy as np

fig = plt.figure()
ax = plt.axes(polar=True)
ax.set_thetalim(0., np.pi/4.)
ax.set_rlim(0., 2.)

# set the size of theta ticklabels (works)
thetatick_locs = np.linspace(0.,45.,4)
thetatick_labels = [u'%i\u00b0'%np.round(x) for x in thetatick_locs]
ax.set_thetagrids(thetatick_locs, thetatick_labels, fontsize=16)

# set the size of r ticklabels (does not work)
rtick_locs = np.arange(0.5,2.0,0.7)
rtick_labels = ['%.1f'%r for r in rtick_locs]
ax.set_rgrids(rtick_locs, rtick_labels, fontsize=16)

plt.show()

Actual outcome
See figure

Expected outcome
I expect to be able to set the font properties of r ticklabels. Other settings, such as trying to set the font weight, does not work either.

Matplotlib version

  • Operating system: Macos 10.15.4 (Catalina)
  • Matplotlib version: 3.2.1 (installed via macports)
  • Matplotlib backend: Qt5Agg
  • Python version: 3.8.2 (installed via macports)
@AgilentGCMS AgilentGCMS changed the title set_rgrids() in a polar plot does not set ticklabel size set_rgrids() in a polar plot cannot set ticklabel size May 20, 2020
@QuLogic
Copy link
Member

QuLogic commented May 21, 2020

I think this is because the radial ticks are re-created on draw to take into account the changed theta limits. A workaround is to call fig.canvas.draw() before calling set_rgrids.

@AgilentGCMS
Copy link
Author

Yes, fig.canvas.draw() before set_rgrids fixed the problem. This is a good workaround, but I think there should be a fix, which would attach the font properties to the tick labels, to be used every time the canvas is drawn.

@CatChenal
Copy link

In case @AgilentGCMS has not found a workaround, here is one (although I could not find a way to offset the labels from the edge):

from matplotlib import pyplot as plt
import numpy as np

fig = plt.figure(figsize=(5, 5))
ax = plt.axes(polar=True)
ax.set_thetalim(0., np.pi/4.)
ax.set_rlim(0., 2.)

# set the size of theta ticklabels (works)
thetatick_locs = np.linspace(0.,45.,4)
thetatick_labels = [u'%i\u00b0'%np.round(x) for x in thetatick_locs]
ax.set_thetagrids(thetatick_locs, thetatick_labels, fontsize=16)

# set the size of r ticklabels (does not work)
rtick_locs = np.arange(0.5,2.0,0.7)
rtick_labels = ['%.1f'%r for r in rtick_locs]

# Workaround using ax.text (caveat: doesn't offset labels from edge)
#ax.set_rgrids(rtick_locs, rtick_labels, fontsize=16)

ax.set_yticklabels([])
for loc, lbl in zip(rtick_locs, rtick_labels):
    ax.text(0., loc, lbl,
            ha='center',
            va='top', 
            fontsize=16)

plt.show();


wedge

@AgilentGCMS
Copy link
Author

@CatChenal I used the workaround of @QuLogic

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Aug 2, 2023
@timhoffm
Copy link
Member

timhoffm commented Aug 2, 2023

In general, the problem with kwargs on set_*grids is that these apply only to the then defined tick instances.

Various operations can create/delete/modify these so that there is no guarantee these properties are maintained.

The better approach is to use ax.tick_params(labelsize=16) here, which defines the Axis-defaults and suvives any further operations.

#26436 documents this. Further work options

a) close because it's documented.

b) deprecate kwargs (argument: Setting individual tick properties should be transparent to the user and they should do it explicitly themselves). This would be intentionally be more cumbersome and drive people towards set_tick_params. The risk is to annoy users, where this currently worked.

c) translate **kwargs to setting tick_params. This is conceptually reasonable, but there is not a simple 1:1 mapping, both naming wise, and not all Text kwargs are exposed via tick_params. So doing this properly would be cumbersome.

I suggest to stick with a).

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants