dateformatter#

dateformatter(ax=None, style='sciris', dateformat=None, start=None, end=None, rotation=None, locator=None, axis='x', **kwargs)[source]#

Format the x-axis to use a given date formatter.

By default, this will apply the Sciris date formatter to the current x-axis. This formatter is a combination of Matplotlib’s Concise date formatter, and Plotly’s date formatter.

See also sc.datenumformatter() to convert a numeric axis to date labels.

Parameters:
  • ax (axes) – if supplied, use these axes instead of the current one

  • style (str) – the style to use if the axis already uses dates; options are “sciris”, “auto”, “concise”, or a Formatter object

  • dateformat (str) – the date format (default '%Y-%b-%d'; not needed if x-axis already uses dates)

  • start (str/int) – if supplied, the lower limit of the axis

  • end (str/int) – if supplied, the upper limit of the axis

  • rotation (float) – rotation of the labels, in degrees

  • locator (Locator) – if supplied, use this instead of the default AutoDateLocator locator

  • axis (str) – which axis to apply to the formatter to (default ‘x’)

  • kwargs (dict) – passed to the date formatter (e.g., ScirisDateFormatter)

Examples:

# Reformat date data
pl.figure()
x = sc.daterange('2021-04-04', '2022-05-05', asdate=True)
y = sc.smooth(pl.rand(len(x)))
pl.plot(x, y)
sc.dateformatter()

# Configure with Matplotlib's Concise formatter
fig,ax = pl.subplots()
pl.plot(sc.date(np.arange(365), start_date='2022-01-01'), pl.randn(365))
sc.dateformatter(ax=ax, style='concise')
New in version 1.2.0.
New in version 1.2.2: “rotation” argument; renamed “start_day” to “start_date”
New in version 1.3.0: refactored to use built-in Matplotlib date formatting
New in version 1.3.2: “axis” argument
New in version 1.3.3: split sc.dateformatter() from sc.datenumformatter()