| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| units.registry[datetime.date] = DateConverter() | ||
| units.registry[datetime.datetime] = DateConverter() | ||
|
|
||
| def register_converters(): |
There was a problem hiding this comment.
This logic should really be in a _validate_date_converter validator, no? otherwise that means that setting the rcParam from anywhere but the matplotlibrc would have no effect.
(And yes, that means we may either need to try to import matplotlib.dates in rcsetup, or, if that's not possible, special case initial import time and re-validate once we import matplotlib.dates).
Sorry, something went wrong.
There was a problem hiding this comment.
Does a validator get called every time the rcParam dict is updated? I guess that would be a good way to do that, if a little magical.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes
Sorry, something went wrong.
There was a problem hiding this comment.
Is there an easy way to tell if the validation is the initial one or a subsequent one? Because if not, I'm not convinced this is worth the bother.
Sorry, something went wrong.
|
I agree this seems reasonable, but share @anntzer 's concern that as written it won't trigger when the rcparams are changed. |
Sorry, something went wrong.
|
Unless someone has a straightforward way to update the converter during the init of the rcParams without importing datetime, I'm not convinced the magic of being able to change the rcParam on the fly is worthwhile. People can just call the new mdates.set_converters if they need to change the rcParams during a script. |
Sorry, something went wrong.
|
ok, but in that case you need at least to block updating of the rcParam once matplotlib is imported (again, with a custom validator) (and even then I doubt I'd accept the feature). I don't like that solution but I think it's expected (well, at least I expect) that setting a variable in the matplotlibrc is equivalent to setting it in python code, so if it's not at least it should error out cleanly. |
Sorry, something went wrong.
|
Well again is there an easy way to know if the validator is being run for first time? If not I don’t see how this can work. Frankly I think the magic imbued in rcParams is needlessly complicated and we should not think of it as something that must allow real time toggles for everything. |
Sorry, something went wrong.
|
It's not so much called once as called from the matplotlibrc, I'm sure the right amount of stack walking could work. |
Sorry, something went wrong.
|
OK, not ridiculously ugly. I just bail if the matplotlib.dates import fails... |
Sorry, something went wrong.
|
Much better :) |
Sorry, something went wrong.
|
... I forgot about this one. Its now rebased and should be ready for review... |
Sorry, something went wrong.
|
|
||
| class _rcParam_helper: | ||
| """ | ||
| Never instatiated, but manages the rcParams for dates... |
There was a problem hiding this comment.
perhaps merge the comment above and the docstring...
Sorry, something went wrong.
| converter = DateConverter | ||
|
|
||
| interval_multiples = cls.int_mult | ||
| print(interval_multiples) |
There was a problem hiding this comment.
remove this?
Sorry, something went wrong.
There was a problem hiding this comment.
Ooops
Sorry, something went wrong.
|
|
||
| interval_multiples = cls.int_mult | ||
| print(interval_multiples) | ||
| units.registry[np.datetime64] = converter( |
There was a problem hiding this comment.
perhaps just instantiate a single converter and assign to all 3?
Sorry, something went wrong.
There was a problem hiding this comment.
... I guess so? the old code instantiated three converters, so I'm a little hesitant. OTOH, I'm not sure why it did, and I don't think we lose any flexibility this way...
Sorry, something went wrong.
| try: | ||
| import matplotlib.dates as mdates | ||
| mdates._rcParam_helper.set_converter(s) | ||
| except Exception as e: |
There was a problem hiding this comment.
add a comment that this can only fail at initial import time?
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah - so this gives me a bit of pause. Does this cause any import slowdowns?
Sorry, something went wrong.
There was a problem hiding this comment.
I guess you could write mdates = sys.modules.get("matplotlib.dates"); if mdates: ... as matplotlib.dates will be in sys.modules once everything is set up properly...
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks, I prefer that....
Sorry, something went wrong.
There was a problem hiding this comment.
@jklymak do you still want to change how this is written?
Sorry, something went wrong.
There was a problem hiding this comment.
Needs perhaps a few comments/docstring fixes, but other than that looks fine to me.
Sorry, something went wrong.
There was a problem hiding this comment.
Add doc in ConciseDateFormatter
Sorry, something went wrong.
There was a problem hiding this comment.
Modulo a example with a plot in the whats new.
Sorry, something went wrong.
|
|
||
| def __init__(self, formats=None, zero_formats=None, offset_formats=None, | ||
| show_offset=True): | ||
| show_offset=True, interval_multiples=True): |
There was a problem hiding this comment.
kwonly?
Sorry, something went wrong.
There was a problem hiding this comment.
sure
Sorry, something went wrong.
|
|
||
| @staticmethod | ||
| def axisinfo(unit, axis): | ||
| def __init__(self, interval_multiples=True): |
There was a problem hiding this comment.
kwonly?
Sorry, something went wrong.
There was a problem hiding this comment.
sure
Sorry, something went wrong.
| plt.rcParams['date.converter'] = 'auto' | ||
| plt.rcParams['date.interval_multiples'] = False | ||
| ax = axs[1] | ||
| ax.plot(dates, y) |
There was a problem hiding this comment.
This renders as https://39494-1385122-gh.circle-artifacts.com/0/doc/build/html/users/next_whats_new/rcparams_dates.html I'm forgetting how to get the plot to show in the docs? OK figured it out
Sorry, something went wrong.
|
New Whats new w example: https://39836-1385122-gh.circle-artifacts.com/0/doc/build/html/users/next_whats_new/rcparams_dates.html |
Sorry, something went wrong.
Ooops, duh - I missed one of the two cases. Thanks for pointing that out. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
This is a proposal for two new date rcParam entries:
date.converter which takes a string. If its 'concise' then mdates.ConciseDateConverter is used for dates, otherwise mdates.AutoDateConverter is used (as before). Default is the same as before: 'auto'
date.interval_multiples sets whether 'interval_multiples' is used (True by default) for the auto locators.
Note this needs a new mdates.register_converters to work after matplotlib.dates has been imported by matplotlib.pyplot. EDIT: fixed to allow automatic changing of the rcParams....
Needs tests and a what's new...
PR Checklist