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
[Bug]: Can't obviously control radial ticks on polar plot #22104
The fontsize argument of ax.set_xticklabels() controls the size of azimuthal tick labels on a polar plot.
However the same argument, when passed to set_yticklabels(), does not control the size of radial tick labels. In fact it does nothing - the value of the argument has no impact on the plot.
To modify the size of radial tick labels, one must call: ax.yaxis.set_tick_params(labelsize='large')
This is not obvious.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnp# Make fake datad=np.random.rand(11,18)
azimuths=np.radians(np.arange(-42.5,42.6,5))
radials=np.linspace(1.3,3.9,11)
r, theta=np.meshgrid(radials, azimuths)
# Plot the datafig=plt.figure(figsize=(6,6))
ax1=fig.add_subplot(111,polar=True)
cont=ax1.contourf(theta, r, np.fliplr(d).T,
)
ax1.set_theta_zero_location('N')
ax1.set_thetamin(-45)
ax1.set_thetamax(45)
ax1.set_xticks(np.arange(np.radians(-45),
np.radians(46),
np.radians(15),
)) # Less radial ticksax1.set_xticklabels(np.arange(-45,46,15)[::-1],
fontsize='xx-large', # This argument controls azimuthal tick labels
)
ax1.set_yticklabels(np.arange(-45,46,15)[::-1],
fontsize='xx-large', # So why does this not control the radial tick labels?
)
# ax1.yaxis.set_tick_params(labelsize='xx-large') # Especially when this line *does* control themplt.show()
Actual outcome
Here you can see that the radial tick labels are too small, unaffected by the set_yticklabels command:
Expected outcome
They should be this size. The following is produced by using the set_tick_params command:
Without checking (I’m currently away from my dev machine) I suspect that set*ticklabels kwargs only sets the properties of the tick labels defined therein, but not the general tick label properties. - We should discuss whether that’s desired or not. This would be a significant behavior change, that needs careful consideration.
I also assume this is only indirectly related to polar. The reason for the difference between r and theta here is likely that you have not set explicit r tick positions (this should give a warning when you set the labels).
@timhoffm Yes, I have looked into this and that seems to be the case. set_yticklabels is only setting the properties of the tick labels passed in, and with polar axes confined to a sector (the example given in the issue) reset_ticks() is called in the draw() function in polar.py (line 958), so the ticks that are created in the following functions do not have the fontsize property set. My current thoughts on fixing this is to call set_tick_params in set_ticklabels (you can see the changes I did in my commit), but it seems that it is a significant behavior change.
My current thoughts on fixing this is to call set_tick_params in set_ticklabels (you can see the changes I did in my commit), but it seems that it is a significant behavior change.
This is indeed a major behavior change, which should be agreed upon by core devs. However, I'm inclinded towards this because I think the sematics of styling in set_ticklabels() is global (not only universal for all the ticks set, but also for future ticks). The major problem I see is that set_tick_params only covers a small portion of Text properties, that one could pass to set_ticklabels() ( from a quick look possibly: labelcolor, labelrotation, labelsize, zorder, and the latter cannot be set independently of the tick line). And different behavior for different parameters would be even worse.
Possibly the first step forward is improving the set_ticklabel and set_ticks docs to state the current behavior that it applies only to the given ticks, and if possible users should use tick_params instead. Everything behavior change is probably a larger effort.
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!
Activity
lxguan1 commentedon Apr 17, 2022
Hi,
I plan on doing a pr for a solution to this issue, but have you found any other examples of this bug occurring?
It seems to be that set_yticklabels does not save the fontweight setting, so when a new tick is created later it does not have the fontweight applied.
Thanks!
Make set_ticklabels save fontsize setting
timhoffm commentedon Apr 18, 2022
Without checking (I’m currently away from my dev machine) I suspect that set*ticklabels kwargs only sets the properties of the tick labels defined therein, but not the general tick label properties. - We should discuss whether that’s desired or not. This would be a significant behavior change, that needs careful consideration.
I also assume this is only indirectly related to polar. The reason for the difference between r and theta here is likely that you have not set explicit r tick positions (this should give a warning when you set the labels).
lxguan1 commentedon Apr 18, 2022
@timhoffm Yes, I have looked into this and that seems to be the case. set_yticklabels is only setting the properties of the tick labels passed in, and with polar axes confined to a sector (the example given in the issue) reset_ticks() is called in the draw() function in polar.py (line 958), so the ticks that are created in the following functions do not have the fontsize property set. My current thoughts on fixing this is to call set_tick_params in set_ticklabels (you can see the changes I did in my commit), but it seems that it is a significant behavior change.
timhoffm commentedon Apr 18, 2022
This is indeed a major behavior change, which should be agreed upon by core devs. However, I'm inclinded towards this because I think the sematics of styling in
set_ticklabels()is global (not only universal for all the ticks set, but also for future ticks). The major problem I see is thatset_tick_paramsonly covers a small portion of Text properties, that one could pass toset_ticklabels()( from a quick look possibly:labelcolor,labelrotation,labelsize,zorder, and the latter cannot be set independently of the tick line). And different behavior for different parameters would be even worse.Possibly the first step forward is improving the
set_ticklabelandset_ticksdocs to state the current behavior that it applies only to the given ticks, and if possible users should usetick_paramsinstead. Everything behavior change is probably a larger effort.github-actions commentedon Dec 3, 2025
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!
rcomer commentedon Dec 3, 2025
set_ticklablelswas formerly discouraged at #20047, and the code from the OP now throws a reasonably clear warning:So I do not think there is anything more to do here. Please comment and/or re-open if you disagree.