Title: [Bug]: X-Axis date label not rotated · Issue #22521 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: X-Axis date label not rotated · Issue #22521 · matplotlib/matplotlib
X Title: [Bug]: X-Axis date label not rotated · Issue #22521 · matplotlib/matplotlib
Description: 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 import matplotlib.pyplot as plt import...
Open Graph Description: 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 reproductio...
X Description: 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 reproductio...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22521
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: X-Axis date label not rotated","articleBody":"### Bug summary\n\nUsing 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.\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nimport matplotlib.dates as mdates\r\nimport datetime\r\n\r\ndates = [datetime.datetime(2022, 2, 21, 0, 0),\r\n datetime.datetime(2022, 2, 22, 0, 0),\r\n datetime.datetime(2022, 2, 27, 0, 0)]\r\ndata1 = [5,8,12]\r\n\r\nfig, ax = plt.subplots(1, 1, figsize=(20/2.54, 12/2.54))\r\nplt.subplots_adjust(left=0.08, bottom=0.15, right=0.95)\r\nplt.title(\"Date x-axis label angle bug\")\r\n\r\nb1 = ax.bar(dates, data1, width=0.7)\r\n\r\n# Setup the date x-axis in weeks marking start of each week start\r\nax.xaxis.set_major_locator(mdates.WeekdayLocator(byweekday=mdates.MO))\r\nax.xaxis.set_major_formatter(mdates.DateFormatter('%a %b %d'))\r\n\r\n# The same problem regardless the method to set the angle\r\n#for label in ax.get_xticklabels(which='major'):\r\n# label.set(rotation=30, horizontalalignment='right')\r\nplt.xticks(rotation=30, ha=\"right\")\r\n\r\n# Add a vline to force the auoscaling outside the data range\r\nplt.axvline(x=datetime.datetime(2022, 3, 15, 0, 0))\r\n\r\nplt.show()\n```\n\n\n### Actual outcome\n\nAs can be seen in the screenshot the Feb 28 label is not rotated.\r\n\r\n\r\n\r\n\n\n### Expected outcome\n\nThat the dates are rotated as in the following screenshot.\r\n\r\n\r\nNote: As long as the initial dates for the available data extends past Feb 28 then the labels are correctly rotated\n\n### Additional information\n\nThis 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.\n\n### Operating system\n\nOSX\n\n### Matplotlib Version\n\n3.5.1\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n3.9.10\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/johan162","@type":"Person","name":"johan162"},"datePublished":"2022-02-21T15:30:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/22521/matplotlib/issues/22521"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c8cab7ac-b88e-a2cf-f543-7b1437fee6bb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 903A:18CEBB:241A65D:3053A93:6A520639 |
| html-safe-nonce | 2870abdda4bde75b1ff5ecfa14215b8e5b98a2bcf3e5189fe485d41639506b05 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDNBOjE4Q0VCQjoyNDFBNjVEOjMwNTNBOTM6NkE1MjA2MzkiLCJ2aXNpdG9yX2lkIjoiNDcwNTcyNjM3MzU2MTUwMTI0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a632a0525895559ef243fce8289fcb1f08b9c8d73f74ffcf07a7499d38a780bb |
| hovercard-subject-tag | issue:1145945342 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/22521/issue_layout |
| twitter:image | https://opengraph.githubassets.com/454062373bc8cc73612d6a9c5642b67208522b7bd5391fdb93e0ce8e321ee970/matplotlib/matplotlib/issues/22521 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/454062373bc8cc73612d6a9c5642b67208522b7bd5391fdb93e0ce8e321ee970/matplotlib/matplotlib/issues/22521 |
| og:image:alt | 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 reproductio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johan162 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width