From 00796b2d1a16265d616491ef4cd0fb2bb02cc67f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 5 Dec 2015 16:42:56 -0500 Subject: [PATCH] DOC: add FAQ about np.datetime64 --- doc/faq/howto_faq.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/faq/howto_faq.rst b/doc/faq/howto_faq.rst index 11c63aceae4a..98c71350e349 100644 --- a/doc/faq/howto_faq.rst +++ b/doc/faq/howto_faq.rst @@ -14,6 +14,35 @@ How-To Plotting: howto =============== +.. _howto-datetime64: + +Plot `numpy.datetime64` values +------------------------------ + +For matplotlib to plot dates (or any scalar with units) a converter +to float needs to be registered with the `matplolib.units` module. The +current best converters for `datetime64` values are in `pandas`. Simply +importing `pandas` :: + + import pandas as pd + +should be sufficient as `pandas` will try to install the converters +on import. If that does not work, or you need to reset `munits.registry` +you can explicitly install the `pandas` converters by :: + + from pandas.tseries import converter as pdtc + pdtc.register() + +If you only want to use the `pandas` converter for `datetime64` values :: + + from pandas.tseries import converter as pdtc + import matplotlib.units as munits + import numpy as np + + munits.registry[np.datetime64] = pdtc.DatetimeConverter() + + + .. _howto-findobj: Find all objects in a figure of a certain type