Timeseries

D3Blocks.timeseries(df, datetime='datetime', dt_format: str = '%d-%m-%Y %H:%M:%S', sort_on_date=True, whitelist=None, fontsize=10, cmap='Set1', title='Timeseries - D3blocks', filepath='timeseries.html', figsize=[1200, 500], showfig=True, overwrite=True, notebook=False, save_button: bool = True, return_html: bool = False, reset_properties=True)

Timeseries block.

The TimeSeries can be used in case a date-time element is available, and where the time-wise values directly follow up with each other. The TimeSeries block supports enabling/disabling columns of interest, brushing and zooming to quickly focus on regions of interest or plot specific features, such as stocks together in a single chart.

Parameters:
  • df (pd.DataFrame()) – Input data containing the columns “datetime” together with the names of the timeseries to plot.

  • datetime (str, (default: None)) – Column name that contains the datetime.

  • dt_format (str) –

    Date time format.
    • ’%d-%m-%Y %H:%M:%S’.

  • sort_on_date (Bool (default: True)) –

    Sort on date.
    • True: Sort on datetime.

    • False: Do not change the input order.

  • whitelist (str, optional) – Keep only columns containing this (sub)string (case insensitive)

  • fontsize (int, (default: 14)) – Fontsize of the fonts in the circle.

  • cmap (String, (default: 'Set1')) –

    All colors can be reversed with ‘_r’, e.g. ‘binary’ to ‘binary_r’
    • ’tab20c’, ‘Set1’, ‘Set2’, ‘rainbow’, ‘bwr’, ‘binary’, ‘seismic’, ‘Blues’, ‘Reds’, ‘Pastel1’, ‘Paired’, ‘twilight’, ‘hsv’, ‘inferno’

  • title (String, (default: None)) –

    Title of the figure.
    • ’Timeseries’

  • filepath (String, (Default: user temp directory)) –

    File path to save the output.
    • Temporarily path: ‘d3blocks.html’

    • Relative path: ‘./d3blocks.html’

    • Absolute path: ‘c://temp//d3blocks.html’

    • None: Return HTML

  • figsize (tuple) –

    Size of the figure in the browser, [width, height].
    • [1200, 500]

  • showfig (bool, (default: True)) –

    • True: Open browser-window.

    • False: Do not open browser-window.

  • overwrite (bool, (default: True)) –

    • True: Overwrite the html in the destination directory.

    • False: Do not overwrite destination file but show warning instead.

  • notebook (bool) –

    • True: Use IPython to show chart in notebook.

    • False: Do not use IPython.

  • save_button (bool, (default: True)) –

    • True: Save button is shown in the HTML to save the image in svg.

    • False: No save button is shown in the HTML.

  • return_html (bool, (default: False)) –

    • True: Return html

    • False: Nothing is returned

  • reset_properties (bool, (default: True)) –

    • True: Reset the node_properties at each run.

    • False: Use the d3.node_properties()

Returns:

  • d3.node_properties (DataFrame of dictionary) – Contains properties of the unique input label/nodes/samples.

  • d3.edge_properties (DataFrame of dictionary) – Contains properties of the unique input edges/links.

  • d3.config (dictionary) – Contains configuration properties.

Examples

>>> #
>>> # Import
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Import example
>>> df = d3.import_example('climate')
>>> #
>>> # Show
>>> d3.timeseries(df, datetime='date', dt_format='%Y-%m-%d', fontsize=10, figsize=[850, 500])
>>> #

Examples

>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks(chart='Timeseries', frame=False)
>>> #
>>> # Import example
>>> df = d3.import_example('climate')
>>> #
>>> # Node properties
>>> d3.set_node_properties(df.columns.values)
>>> d3.node_properties.get('wind_speed')['color']='#000000'
>>> print(d3.node_properties)
>>> #
>>> d3.set_edge_properties(df, datetime='date', dt_format='%Y-%m-%d')
>>> d3.edge_properties
>>> #
>>> # Show
>>> d3.show(title='Timeseries with adjusted configurations')
>>> #

References

Input Data

The input dataset is a DataFrame for which the index column is the datetime, and the columns are plotted with their column name.

#            Adj Close                      ...    Volume
#                 AAPL      AMZN      META  ...      META      TSLA      TWTR
# Date                                      ...
# 2018-12-31  1.000000  1.000000  1.000000  ...  1.000000  1.000000  1.000000
# 2019-01-02  1.001141  1.024741  1.035014  ...  1.142979  1.849896  0.942329
# 2019-01-03  0.901420  0.998875  1.004958  ...  0.922543  1.105184  1.192595
# 2019-01-04  0.939901  1.048882  1.052330  ...  1.177736  1.173238  1.465577
# 2019-01-07  0.937809  1.084915  1.053093  ...  0.815799  1.198166  1.246811

# [5 rows x 30 columns]

Chart