Basic Usage
Timple provides locator and formatter classes for timedelta-like values. These are similar to Matplotlib’s native formatters and locators for date-like values. They allow for nicer tick locations and labels than Matplotlib can create natively.
Here is an example plot that shows a minimum working example for using Timple:
import datetime
import numpy as np
import matplotlib.pyplot as plt
import timple
tmpl = timple.Timple()
tmpl.enable()
timedeltas = np.array([datetime.timedelta(minutes=(15 * i))
for i in range(100)])
y = np.array([np.exp(-5*x/100) + np.random.random()/25
for x in range(0, 100)])
plt.plot(timedeltas, y)
plt.show()
In this example, Timple is enabled without any further customization.
Timple’s AutoTimedeltaLocator
and AutoTimedeltaFormatter
are used by default.
If you want to customize tick positions and labels, you can manually set
the locators and formatters. This allows for a more fine grained control
over the resulting plot.
See timple.timedelta
for more information.
Timple furthermore provides the ability to optionally patch Matplotlib’s date functionality so that pandas’ NaT datatype is treated like a NaN value. This means that NaT values are then simply skipped when plotting.
- class timple.core.Timple(converter='default', formatter_args=None)[source]
Bases:
object
The
Timple
class is the most important part of this module. It will always be your starting point. It is very simple and its only purpose is to activate the timple module. This is done by registering a custom converter for timedelta values and by patching some internal functionality of Matplotlib.Usage is very straight forward:
import timple tmpl = timple.Timple() tmpl.enable()
This is all that is necessary to get the basic functionality. You can now simply plot timedelta values and reasonable tick locations and formats will be chosen automatically.
If you want to have more control over the result you can find more information on custom tick locations and formatters in
timple.timedelta
- Parameters
(str) (converter) – Default will use the same value as set in Matplotlib’s rcParams for ‘date.converter’. If this value does not exist it will fall back to ‘auto’.
- enable(pd_nat_dates_support=False)[source]
Enables Timple by patching Matplotlib and registering either timedelta.TimedeltaConverter or timedelta.ConciseTimedeltaConverter.
After this, you can plot timedelta values and Matplotlib will automatically choose appropriate locators and formatter which Timple provides.
If you want more control over the result, you can always specify the formatter and locator for a plot manually. See timedelta for more information.
- Parameters
pd_nat_dates_support ((Optional)) – Patch Matplotlib internal functionality to support pandas NaT values when plotting dates too.