-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: X-Axis date label not rotated #22521
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
Comments
Are dates actually needed to trigger this? |
I cannot be absolutely sure but I haven't been able to recreate it with plain text labels. For example
Works as expected. I actually realized there is a trivial workaround and that is to change the order of the adjustment of the labels and additional graph details. So instead of
you swap to
it works since I assume that with the addition of the vline the xmax is adjusted and the full scale range is subjected to the rotation adjustment. So this seems highly likely (but not certain) to be some corner case involving date axis generation. |
@jklymak I can work on this if this is still an issue. Just want to make sure i understand the problem correctly, if the xticks method is used before the axvline method, the date should still rotate as shown in the expected outcome. Is this correct? |
@mylasem Correct, independently of what plotting is done and in what order, all of the ticks should be rotated the same. |
matplotlib/lib/matplotlib/pyplot.py Lines 1817 to 1819 in b36ef47
is probably the cause. We may have more ticks allocated internally than are returned by That said, we haven't specified the behavior of |
Any workarounds ? |
Call fig.draw_without_rendering before rotating the ticks? |
I have the same problem, with the second tick (also a date) being the only one which is not rotated. I am using : And this workaround works for me, thanks! |
The recommended solution from 3.11 on will be the new tick rotations modes introduced in #28968, i.e. here
I'm closing this as there is a current workaround ( |
Bug summary
Using a date x-axis that are being autoscaled outside the initial data range due to the added vline then the first (and only the first) data label gets no rotation.
Code for reproduction
Actual outcome
As can be seen in the screenshot the Feb 28 label is not rotated.
Expected outcome
That the dates are rotated as in the following screenshot.

Note: As long as the initial dates for the available data extends past Feb 28 then the labels are correctly rotated
Additional information
This seems to occur if the autoscale range is forced outside the initial range (as required by the data) by the addition of annotations and/or vlines outside the original x-axis data span.
Operating system
OSX
Matplotlib Version
3.5.1
Matplotlib Backend
No response
Python version
3.9.10
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: