-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
AutoDateFormatter: More customizable formatting #2507
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
Conversation
This allows custom functions to be used for formatting in the style of FuncFormatter. Also in AutoDateFormatter.__call__() the `pos` kwarg should default to `None` I think.
by matplotlib (show usage with `FuncFormatter`)
@@ -545,8 +561,13 @@ def __call__(self, x, pos=0): | |||
fmt = self.scaled[k] | |||
break | |||
|
|||
self._formatter = DateFormatter(fmt, self._tz) | |||
return self._formatter(x, pos) | |||
if isinstance(fmt, basestring): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to use six.string_type
here. @mdboom?
Ok, thanks. Sorry to not think of the compatibility layering myself.. |
might be directly in newer matplotlib (see matplotlib/matplotlib#2507) but we want this to work with older matplotlib, too
@megies - are you familiar with mock? I think this enhancement would be well suited to a mock test, if your game? |
@pelson - actually, I haven't used mock so far and am not really familiar with how to use it best. What aspect and how would you want mock-tested? |
@pelson Do you want to hold this until there is a |
elif six.callable(fmt): | ||
return fmt(x, pos) | ||
else: | ||
raise NotImplementedError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably raise a more descriptive error.
Closing in favour of #2707 |
The
AutoDateFormatter
is a great tool, one does not have to worry about the scaling of the time range. However, I found for myself that only having astrftime
format string as control is not enough. In particular I found it annoying to not be able to get rid of all-zero decimal seconds where possible and have decimal seconds show up where there really are dcimal seconds.The example I added in the docstring should make clear what I mean.
This PR allows custom functions to be used for formatting in the style of
FuncFormatter
.EDIT: I changed the docstring example to using a FuncFormatter so that it looks less hackish and uses matplotlib classes.
I will have to inherit/override this in our project (so that it works across matplotlib versions), but I thought this might be useful for other matplotlib users in future versions as well.
Also in
AutoDateFormatter.__call__()
thepos
kwarg should default toNone
rather than0
, I think.