Skip to content

Commit

Permalink
Fix formatting in docstring for dates
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshnielsen committed Sep 16, 2014
1 parent 81760d7 commit 630f867
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,22 +520,23 @@ class AutoDateFormatter(ticker.Formatter):
>>> formatter = AutoDateFormatter()
>>> formatter.scaled[1/(24.*60.)] = '%M:%S' # only show min and sec
Custom `FunctionFormatter`s can also be used. The following example shows
how to use a custom format function to strip trailing zeros from decimal
seconds and adds the date to the first ticklabel::
>>> def my_format_function(x, pos=None):
... x = matplotlib.dates.num2date(x)
... if pos == 0:
... fmt = '%D %H:%M:%S.%f'
... else:
... fmt = '%H:%M:%S.%f'
... label = x.strftime(fmt)
... label = label.rstrip("0")
... label = label.rstrip(".")
... return label
>>> from matplotlib.ticker import FuncFormatter
>>> formatter.scaled[1/(24.*60.)] = FuncFormatter(my_format_function)
A custom :class:`~matplotlib.ticker.FuncFormatter` can also be used.
The following example shows how to use a custom format function to strip
trailing zeros from decimal seconds and adds the date to the first
ticklabel::
>>> def my_format_function(x, pos=None):
... x = matplotlib.dates.num2date(x)
... if pos == 0:
... fmt = '%D %H:%M:%S.%f'
... else:
... fmt = '%H:%M:%S.%f'
... label = x.strftime(fmt)
... label = label.rstrip("0")
... label = label.rstrip(".")
... return label
>>> from matplotlib.ticker import FuncFormatter
>>> formatter.scaled[1/(24.*60.)] = FuncFormatter(my_format_function)
"""

# This can be improved by providing some user-level direction on
Expand Down

0 comments on commit 630f867

Please sign in to comment.