Title: ENH: new date formatter by jklymak · Pull Request #10841 · matplotlib/matplotlib · GitHub
Open Graph Title: ENH: new date formatter by jklymak · Pull Request #10841 · matplotlib/matplotlib
X Title: ENH: new date formatter by jklymak · Pull Request #10841 · matplotlib/matplotlib
Description: PR Summary Update 22 Sep 2018: New localization mechanism. This can now be localized. Its a bit verbose because there are basically 3*7 = 21 formatting strings. 7 for the normal ticks, 7 for the ticks that are major time divisions (i.e. if ticks are 22 Mar, 1 Apr, 8 Apr, the tick labels will be "22", "Apr", "8". ). I think the default is good, and ISO compliant. The verbose lists of strings allow localization with a bit of work. I include an example of how to create a trivial subclass to encapsulate that customization. Maybe someone more clever than me can come up with a better way to do this. ..its described in detail at https://13776-1385122-gh.circle-artifacts.com/0/home/circleci/project/doc/build/html/gallery/ticks_and_spines/date_concise_formatter.html#sphx-glr-gallery-ticks-and-spines-date-concise-formatter-py [x] still needs tests ping @anntzer and @ImportanceOfBeingErnest who were both interested in how this would localize. Update 4 July 2018 Renamed ConciseDateFormatter and included examples of how to use it. I think mechanisms or dicussion of whether it shoudl be the defautl can be deferred. Certainly its nice to be able to set the date format manually as pointed out by @ImportanceOfBeingErnest below, and the current method allows this, whereas this Formatter has no localization like that. ... This is a proposed new date formatter. I find the Automatic one less than useful, though I appreciate the functional flexibility of the default one. I'd argue the default should be something like this, but apprecaite we are conservative on such matters. This isn't ready for serious review attention yet, but thoughts on the API or the result are welcome... I'll note a couple fo flaws (in my opinion) of the default locator. As per #9801, interval_multiples=True should be the default. Secondly, it would be nice if the locator only located the first and 15th of the month rather than 1, 15, 29. EDIT: added extra info in the "offset" region of the axes. import datetime import numpy as np import matplotlib matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import matplotlib.dates as mdates fig, axs = plt.subplots(2, 3, figsize=(8,8), constrained_layout=True) axs = axs.flatten() if False: for ax in axs: locator = mdates.AutoDateLocator(interval_multiples=True) formatter = mdates.ConciseDateFormatter(locator) ax.yaxis.set_major_locator(locator) ax.yaxis.set_major_formatter(formatter) fname = 'New.png' else: for ax in axs: locator = mdates.AutoDateLocator(interval_multiples=True) formatter = mdates.AutoDateFormatter(locator) ax.yaxis.set_major_locator(locator) ax.yaxis.set_major_formatter(formatter) fname = 'Old.png' ax = axs[0] t0 = datetime.datetime(2009, 1, 20) tf = datetime.datetime(2009, 1, 21) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(days=5), tf + datetime.timedelta(days=5)) ax.set_title('Days', loc='Right') ax = axs[1] t0 = datetime.datetime(2009, 1, 20) tf = datetime.datetime(2009, 3, 21) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(days=15), tf + datetime.timedelta(days=15)) ax.set_title('2 Months', loc='Right') ax = axs[2] t0 = datetime.datetime(2008, 8, 20) tf = datetime.datetime(2010, 3, 21) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(days=105), tf + datetime.timedelta(days=105)) ax.set_title(' Months/Y', loc='Right') ax = axs[3] t0 = datetime.datetime(2005, 8, 20) tf = datetime.datetime(2015, 3, 21) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(days=1005), tf + datetime.timedelta(days=1005)) ax.set_title(' Years', loc='Right') ax = axs[4] t0 = datetime.datetime(2009, 8, 20) tf = datetime.datetime(2009, 8, 21) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(hours=3), tf + datetime.timedelta(hours=3)) ax.set_title(' Hours', loc='Right') ax = axs[5] t0 = datetime.datetime(2009, 8, 20, 9) tf = datetime.datetime(2009, 8, 20, 10) ax.axhspan(t0, tf, facecolor="blue", alpha=0.25) ax.set_ylim(t0 - datetime.timedelta(minutes=3), tf + datetime.timedelta(minutes=3)) ax.set_title(' Minutes', loc='Right') fig.savefig(fname) plt.show() Before: After: PR Checklist Has Pytest style unit tests Code is PEP 8 compliant New features are documented, with examples if plot related Documentation is sphinx and numpydoc compliant Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way
Open Graph Description: PR Summary Update 22 Sep 2018: New localization mechanism. This can now be localized. Its a bit verbose because there are basically 3*7 = 21 formatting strings. 7 for the normal ticks, 7 for the ...
X Description: PR Summary Update 22 Sep 2018: New localization mechanism. This can now be localized. Its a bit verbose because there are basically 3*7 = 21 formatting strings. 7 for the normal ticks, 7 for the ...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/10841
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:675fbf61-80d7-9039-57d3-a542228e2865 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 837C:185C34:21E990A:2E5FF69:6A5396A6 |
| html-safe-nonce | 6649ccb8a80f372fada7afbf44b92cc719778d8cb7699c9e75ca59c02d5e0547 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzdDOjE4NUMzNDoyMUU5OTBBOjJFNUZGNjk6NkE1Mzk2QTYiLCJ2aXNpdG9yX2lkIjoiNTA0MzI3OTkwMDczNzUwOTAzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a97e1ff31b261a909e437518b73910a489e424f8a948b9a18314a6c688058065 |
| hovercard-subject-tag | pull_request:175971279 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/10841/files |
| twitter:image | https://avatars.githubusercontent.com/u/1562854?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1562854?s=400&v=4 |
| og:image:alt | PR Summary Update 22 Sep 2018: New localization mechanism. This can now be localized. Its a bit verbose because there are basically 3*7 = 21 formatting strings. 7 for the normal ticks, 7 for the ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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