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
No support for horizontal alignment in tick_params? #13774
There is a bit of discussion in #10911 (comment) and following comments.
As to why it isn't implemented, the answer is simply noone has done it yet. The tick params used to be a big mess; by now it has become much cleaner code-wise. So maybe now is the time to actually add the missing properties.
Note: The horizontal alignment of Text is is something different compared to what's probably expected from horizontal alignment of tick labels. Text aligns itself relative to its reference point. The ticks should probably align to a common reference line. See the discussion in #13440.
I'm not in favour of overloading the notion horizontalalignment with different things. What I would expect and find useful is exactly what horizontalalignment does for text. Though of course one can introduce additional options like horizontalalignment="leftjustify" for the thing proposed in #13440.
I‘m not suggesting if or how to handle this. But horizontalalignment="left" is probably not that useful here. It basically would result in this example: #13440 (comment)
One could hence argue that setters are the way to set the properties of ticklabels in matplotlib. But, since the introduction of tick_params, there are some cases where those properties are overwritten by a more general axis-wide setting. An example of this is precisely #10911 (comment). It was hence argued that tick_params should be the recommended interface to set those properties; but if that is to be the case, clearly horizontalalignment, verticalalignment and rotation_mode are missing.
So more generally, one could summarize this into the question: What is the recommended interface to set axis label properties in matplotlib?
(And please read through #10911 completely, before trying to answer that question. Also, a similar issue is #10882)
Reacted by Oskar Hint, Bhaskar-JR, Mustapha AJEGHRIR, alkatar21, Benjamin Carver, Medrine Waeni, Lukas Hergt, Joshua Schaaf, Euxhen Hasanaj and Diane M. Napolitano
Disclaimer: Did not take the time to read #10911 completely, but still want to give short feedback. Please let me know in case I'm completely out of context.
From my naive point of view, your use case looks valid; and I would expect to be able to use tick_params there. Shall we maybe restrict horizontalalignment to xaxis and verticalalignment to yaxis` to not raise any false expectations concerning the not supported justify-alignment.
Following the principle of least astonishment I'd say that if specifiying ax.tick_params(axis="y", horizontalalignment="left") one would expect the horizontalalignment to apply to the y axis. This is still useful in conjunction with pad, e.g. ax.tick_params(axis="y", horizontalalignment="left", pad=-5) would give:
or ax.tick_params(axis="y", horizontalalignment="left", pad=20)
Worth noting: The "justify" case can currently be accomplished via mpl_toolkits.axisartist as shown in the demo_ticklabel_alignment example.
Should we maybe allow the alignment parameters only for single axis? For ax.tick_params(axis="y", horizontalalignment="left") the alignment has quite different effects and it would be a rare usecase that this is desired behavior. OTOH it's not too bad leaving this up to the user.
@PBrockmann there is no out-of-the-box solution yet because the meaning of alignment is somewhat subtle. See the discussions above for details.
Therefore, alignment is currently not available in tick_params. As a workaround, you can set the alignment on the individual ticklabel instances plt.setp(second_xaxis.get_xticklabels(), horizontalalignment='left'). This works for static plots, i.e. as long as you don't modify the ticks afterwards.
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
ImportanceOfBeingErnest commentedon Mar 28, 2019
There is a bit of discussion in #10911 (comment) and following comments.
As to why it isn't implemented, the answer is simply noone has done it yet. The tick params used to be a big mess; by now it has become much cleaner code-wise. So maybe now is the time to actually add the missing properties.
timhoffm commentedon Mar 30, 2019
Note: The horizontal alignment of
Textis is something different compared to what's probably expected from horizontal alignment of tick labels.Textaligns itself relative to its reference point. The ticks should probably align to a common reference line. See the discussion in #13440.ImportanceOfBeingErnest commentedon Mar 30, 2019
I'm not in favour of overloading the notion
horizontalalignmentwith different things. What I would expect and find useful is exactly whathorizontalalignmentdoes fortext. Though of course one can introduce additional options likehorizontalalignment="leftjustify"for the thing proposed in #13440.timhoffm commentedon Mar 30, 2019
I‘m not suggesting if or how to handle this. But
horizontalalignment="left"is probably not that useful here. It basically would result in this example: #13440 (comment)ImportanceOfBeingErnest commentedon Mar 30, 2019
I don't think we need to question the usefulness. But let me reiterate.
As an example, consider using long ticklabels as in A simple categorical heatmap. You want them to be right-aligned and rotated
which is achieved using setters via
One could hence argue that setters are the way to set the properties of ticklabels in matplotlib. But, since the introduction of
tick_params, there are some cases where those properties are overwritten by a more general axis-wide setting. An example of this is precisely #10911 (comment). It was hence argued thattick_paramsshould be the recommended interface to set those properties; but if that is to be the case, clearlyhorizontalalignment,verticalalignmentandrotation_modeare missing.So more generally, one could summarize this into the question: What is the recommended interface to set axis label properties in matplotlib?
(And please read through #10911 completely, before trying to answer that question. Also, a similar issue is #10882)
timhoffm commentedon Apr 2, 2019
Disclaimer: Did not take the time to read #10911 completely, but still want to give short feedback. Please let me know in case I'm completely out of context.
From my naive point of view, your use case looks valid; and I would expect to be able to use
tick_paramsthere. Shall we maybe restricthorizontalalignmentto xaxis andverticalalignment toyaxis` to not raise any false expectations concerning the not supported justify-alignment.ImportanceOfBeingErnest commentedon Apr 3, 2019
Following the principle of least astonishment I'd say that if specifiying
ax.tick_params(axis="y", horizontalalignment="left")one would expect the horizontalalignment to apply to the y axis. This is still useful in conjunction withpad, e.g.ax.tick_params(axis="y", horizontalalignment="left", pad=-5)would give:or
ax.tick_params(axis="y", horizontalalignment="left", pad=20)Worth noting: The "justify" case can currently be accomplished via
mpl_toolkits.axisartistas shown in the demo_ticklabel_alignment example.timhoffm commentedon Apr 14, 2019
@ImportanceOfBeingErnest you are right with your example.
Should we maybe allow the alignment parameters only for single
axis? Forax.tick_params(axis="y", horizontalalignment="left")the alignment has quite different effects and it would be a rare usecase that this is desired behavior. OTOH it's not too bad leaving this up to the user.mooperd commentedon Nov 28, 2020
+1
5 remaining items
story645 commentedon Oct 27, 2021
xref #20644
PBrockmann commentedon Sep 15, 2024
With 3.9.2, I haven't be able to control anchor position for xticklabels especially in a secondary_xaxis.
The parameter 'ha' is missing in
second_xaxis.tick_params(labelrotation=30, labelsize=8)Am I missing something ?
timhoffm commentedon Sep 17, 2024
@PBrockmann there is no out-of-the-box solution yet because the meaning of alignment is somewhat subtle. See the discussions above for details.
Therefore, alignment is currently not available in
tick_params. As a workaround, you can set the alignment on the individual ticklabel instancesplt.setp(second_xaxis.get_xticklabels(), horizontalalignment='left'). This works for static plots, i.e. as long as you don't modify the ticks afterwards.PBrockmann commentedon Sep 17, 2024
Ok thanks ! It works.
See https://github.com/PBrockmann/PyAnalyseries
I was expecting a control on a specific axe rather than with plt.
Label Aligment Issue matplotlib#20644 with Horizontal Support matplot…
github-actions commentedon Sep 19, 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!
timhoffm commentedon Sep 19, 2025
Discussion is continued in #20644