Register pandas formatters and converters with matplotlib.
This function modifies the global matplotlib.units.registry dictionary. pandas adds custom converters for
pd.Timestamp
pd.Period
np.datetime64
datetime.datetime
datetime.date
datetime.time
See also
deregister_matplotlib_convertersRemove pandas formatters and converters.
Examples
The following line is done automatically by pandas so the plot can be rendered:
>>> pd.plotting.register_matplotlib_converters()
>>> df = pd.DataFrame({'ts': pd.period_range('2020', periods=2, freq='M'),
... 'y': [1, 2]
... })
>>> plot = df.plot.line(x='ts', y='y')
Unsetting the register manually an error will be raised:
>>> pd.set_option("plotting.matplotlib.register_converters",
... False)
>>> df.plot.line(x='ts', y='y')
Traceback (most recent call last):
TypeError: float() argument must be a string or a real number, not 'Period'
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.plotting.register_matplotlib_converters.html