Plot time series

plot_utils.plot_multiple_timeseries(multiple_time_series, show_legend=True, fig=None, ax=None, figsize=(10, 3), dpi=100, ncol_legend=5, **kwargs)[source]

Plot multiple time series.

Note that setting keyword arguments such as color or linestyle will force all time series to have the same color or line style. So we recommend letting this function generate distinguishable line specifications (color/ linestyle/linewidth combinations) by itself. (Although the more time series, the less the distinguishability. 240 time series or less is recommended.)

Parameters:
  • multiple_time_series (pandas.DataFrame or pandas.Series) – If it is a pandas DataFrame, its index is the date, and each column is a different time series. If it is a pandas Series, it will be internally converted into a 1-column pandas DataFrame.

  • fig (matplotlib.figure.Figure or None) – Figure object. If None, a new figure will be created.

  • ax (matplotlib.axes._subplots.AxesSubplot or None) – Axes object. If None, a new axes will be created.

  • figsize ((float, float)) – Figure size in inches, as a tuple of two numbers. The figure size of fig (if not None) will override this parameter.

  • dpi (float) – Figure resolution. The dpi of fig (if not None) will override this parameter.

  • ncol_legend (int) – Number of columns of the legend.

  • **kwargs – Other keyword arguments to be passed to plot_timeseries(), such as color, marker, fontsize, alpha, etc.

Returns:

  • fig (matplotlib.figure.Figure) – The figure object being created or being passed into this function.

  • ax (matplotlib.axes._subplots.AxesSubplot) – The axes object being created or being passed into this function.

See also

plot_timeseries()

Plot a single set of time series.

plot_utils.plot_timeseries(time_series, date_fmt=None, fig=None, ax=None, figsize=(10, 3), dpi=100, xlabel='Time', ylabel=None, label=None, color=None, lw=2, ls=None, marker=None, fontsize=12, xgrid_on=True, ygrid_on=True, title=None, zorder=None, alpha=1.0, month_grid_width=None)[source]

Plot time series (i.e., values a function of dates).

You can plot multiple time series by supplying a multi-column pandas Dataframe, but you cannot use custom line specifications (colors, width, and styles) for each time series. It is recommended to use plot_multiple_timeseries() in stead.

Parameters:
  • time_series (pandas.Series or pandas.DataFrame) – A pandas Series, with index being date; or a pandas DataFrame, with index being date, and each column being a different time series.

  • date_fmt (str) – Date format specifier, e.g., ‘%Y-%m’ or ‘%d/%m/%y’.

  • fig (matplotlib.figure.Figure or None) – Figure object. If None, a new figure will be created.

  • ax (matplotlib.axes._subplots.AxesSubplot or None) – Axes object. If None, a new axes will be created.

  • figsize ((float, float)) – Figure size in inches, as a tuple of two numbers. The figure size of fig (if not None) will override this parameter.

  • dpi (float) – Figure resolution. The dpi of fig (if not None) will override this parameter.

  • xlabel (str) – Label of X axis. Usually “Time” or “Date”.

  • ylabel (str) – Label of Y axis. Usually the meaning of the data, e.g., “Gas price [$]”.

  • label (str) – Label of data, for plotting legends.

  • color (list<float> or str) – Color of line. If None, let Python decide for itself.

  • xgrid_on (bool) – Whether or not to show vertical grid lines (default: True).

  • ygrid_on (bool) – Whether or not to show horizontal grid lines (default: True).

  • title (str) – Figure title (optional).

  • zorder (float) – Set the zorder for lines. Higher zorder are drawn on top.

  • alpha (float) – Opacity of the line.

  • month_grid_width (float) – the on-figure “horizontal width” that each time interval occupies. This value determines how X axis labels are displayed (e.g., smaller width leads to date labels being displayed with 90 deg rotation). Do not change this unless you really know what you are doing.

Returns:

  • fig (matplotlib.figure.Figure) – The figure object being created or being passed into this function.

  • ax (matplotlib.axes._subplots.AxesSubplot) – The axes object being created or being passed into this function.

See also

plot_multiple_timeseries()

Plot multiple time series, with the ability to specify different line specifications for each line.