Title: matplotlib cutsom style sheet: format dates with new line character · Issue #15813 · matplotlib/matplotlib · GitHub
Open Graph Title: matplotlib cutsom style sheet: format dates with new line character · Issue #15813 · matplotlib/matplotlib
X Title: matplotlib cutsom style sheet: format dates with new line character · Issue #15813 · matplotlib/matplotlib
Description: Bug report Bug summary In my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., %b %d\n%H:%M. But matplotlib will not recognize the new line character and instead prints \n a...
Open Graph Description: Bug report Bug summary In my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., %b %d\n%H:%M. But matplotlib will not recognize the ne...
X Description: Bug report Bug summary In my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., %b %d\n%H:%M. But matplotlib will not recognize the ne...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/15813
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"matplotlib cutsom style sheet: format dates with new line character","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\nIn my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., `%b %d\\n%H:%M`. But matplotlib will not recognize the new line character and instead prints `\\n` as text on my figure.\r\n\r\nMore details here: https://stackoverflow.com/questions/59144140/matplotlib-cutsom-style-sheet-format-dates-with-new-line-character?noredirect=1#comment104516325_59144140\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n\r\nIn my `my_style.mplstyle` file, I have this formatting instruction for the dates (note the new line character):\r\n\r\n```python\r\n date.autoformatter.hour : %b %d\\n%H:%M\r\n```\r\n\r\nWhen I load the style sheet and make a plot with dates on the x axis, it displays the \\n as text rather than recognizing it as a new line character.\r\n\r\n```python\r\n import matplotlib.pyplot as plt\r\n plt.style.use('my_style')\r\n import pandas as pd\r\n from datetime import datetime\r\n DATES = pd.date_range(datetime(2019, 1, 1), datetime(2019, 1, 2), 6)\r\n plt.plot(DATES, range(len(DATES)))\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n\r\n```\r\n# If applicable, paste the console output here\r\n#\r\n#\r\n```\r\n\r\n**Expected outcome**\r\n\r\n\u003c!--A description of the expected outcome from the code snippet--\u003e\r\n\u003c!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on--\u003e\r\n \r\nI can get the desired outcome if I use the manual method to change the date formats directly in my code, but I would rather avoid repeating these lines of code in all my plotting scripts. That is why I want to use the style sheet to do this.\r\n\r\n```python\r\n import matplotlib.dates as mdates\r\n myFmt = mdates.DateFormatter('%b %d\\n%H:%M')\r\n plt.plot(DATES, range(len(DATES)))\r\n plt.gca().xaxis.set_major_formatter(myFmt)\r\n```\r\n\r\n\r\n\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Windows\r\n * Matplotlib version: 3.1.2\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): module://ipykernel.pylab.backend_inline\r\n * Python version: 3.7.4\r\n * Jupyter version (if applicable): \r\n * Other libraries: \r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\nInstalled from conda\r\n","author":{"url":"https://github.com/blaylockbk","@type":"Person","name":"blaylockbk"},"datePublished":"2019-12-02T19:43:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/15813/matplotlib/issues/15813"}
| 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:dfc36840-6385-f576-82dd-019911c2ea7a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C084:3DC17:3752D0:4D213B:6A53744A |
| html-safe-nonce | 2dffe36d6c6330856dda0801a2178a859717af3debb937a77532be151bab3e74 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDg0OjNEQzE3OjM3NTJEMDo0RDIxM0I6NkE1Mzc0NEEiLCJ2aXNpdG9yX2lkIjoiODA0NzEzNTgyNjkyNjI3NTMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4f21fef3494f129ad6ec56ff1280f88052b7a29c15e8f32e63dc6c7673550d07 |
| hovercard-subject-tag | issue:531495794 |
| 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/15813/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd7b6f27fdbe90e202ba3b4ac847f47deb7c5afd6e8f3e33badc59f574d5fd4e/matplotlib/matplotlib/issues/15813 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd7b6f27fdbe90e202ba3b4ac847f47deb7c5afd6e8f3e33badc59f574d5fd4e/matplotlib/matplotlib/issues/15813 |
| og:image:alt | Bug report Bug summary In my custom matplotlib style sheet, I want to format the dates in such a way that includes a new line character, i.e., %b %d\n%H:%M. But matplotlib will not recognize the ne... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | blaylockbk |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width