You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
set_rgrids() in a polar plot cannot set ticklabel size #17463
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
frommatplotlibimportpyplotaspltimportnumpyasnpfig=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) forxinthetatick_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'%rforrinrtick_locs]
ax.set_rgrids(rtick_locs, rtick_labels, fontsize=16)
plt.show()
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)
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
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.
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.
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();
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!
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.
Activity
[-]set_rgrids() in a polar plot does not set ticklabel size[/-][+]set_rgrids() in a polar plot cannot set ticklabel size[/+]QuLogic commentedon 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 callingset_rgrids.AgilentGCMS commentedon May 21, 2020
Yes,
fig.canvas.draw()beforeset_rgridsfixed 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 commentedon May 21, 2020
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):
AgilentGCMS commentedon May 23, 2020
@CatChenal I used the workaround of @QuLogic
github-actions commentedon 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!
timhoffm commentedon Aug 2, 2023
In general, the problem with
kwargsonset_*gridsis 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
**kwargsto 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).