Skip to content

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

Open

Description

@AgilentGCMS

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)

Activity

  1. changed the title [-]set_rgrids() in a polar plot does not set ticklabel size[/-] [+]set_rgrids() in a polar plot cannot set ticklabel size[/+] on May 20, 2020
  2. QuLogic commented on May 21, 2020

    @QuLogic
    Member

    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.

  3. AgilentGCMS commented on May 21, 2020

    @AgilentGCMS
    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.

  4. CatChenal commented on May 21, 2020

    @CatChenal

    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

  5. AgilentGCMS commented on May 23, 2020

    @AgilentGCMS
    Author

    @CatChenal I used the workaround of @QuLogic

  6. github-actions commented on Aug 2, 2023

    @github-actions

    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!

  7. timhoffm commented on Aug 2, 2023

    @timhoffm
    Member

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions