Skip to content

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

Closed

Conversation

megies
Copy link
Contributor

@megies megies commented Oct 9, 2013

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 a strftime 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__() the pos kwarg should default to None rather than 0, I think.

megies added 2 commits October 9, 2013 13:45
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):
Copy link
Member

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?

@megies
Copy link
Contributor Author

megies commented Oct 9, 2013

Ok, thanks. Sorry to not think of the compatibility layering myself..

megies added a commit to megies/obspy that referenced this pull request Oct 9, 2013
might be directly in newer matplotlib (see matplotlib/matplotlib#2507)
but we want this to work with older matplotlib, too
@pelson
Copy link
Member

pelson commented Oct 9, 2013

@megies - are you familiar with mock? I think this enhancement would be well suited to a mock test, if your game?

@megies
Copy link
Contributor Author

megies commented Oct 9, 2013

@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?

@tacaswell
Copy link
Member

@pelson Do you want to hold this until there is a mock test?

elif six.callable(fmt):
return fmt(x, pos)
else:
raise NotImplementedError()
Copy link
Member

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.

@pelson pelson mentioned this pull request Jan 7, 2014
@pelson
Copy link
Member

pelson commented Jan 7, 2014

Closing in favour of #2707

@pelson pelson closed this Jan 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants