Timeseries
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.
- param df:
Input data containing the columns “datetime” together with the names of the timeseries to plot.
- type df:
pd.DataFrame()
- param datetime:
Column name that contains the datetime.
- type datetime:
str, (default: None)
- param dt_format:
- Date time format.
‘%d-%m-%Y %H:%M:%S’.
- type dt_format:
str
- param sort_on_date:
- Sort on date.
True: Sort on datetime.
False: Do not change the input order.
- type sort_on_date:
Bool (default: True)
- param whitelist:
Keep only columns containing this (sub)string (case insensitive)
- type whitelist:
str, optional
- param fontsize:
Fontsize of the fonts in the circle.
- type fontsize:
int, (default: 14)
- param cmap:
- 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’
- type cmap:
String, (default: ‘Set1’)
- param title:
- Title of the figure.
‘Timeseries’
- type title:
String, (default: None)
- param filepath:
- File path to save the output.
Temporarily path: ‘d3blocks.html’
Relative path: ‘./d3blocks.html’
Absolute path: ‘c://temp//d3blocks.html’
None: Return HTML
- type filepath:
String, (Default: user temp directory)
- param figsize:
- Size of the figure in the browser, [width, height].
[1200, 500]
- type figsize:
tuple
- param showfig:
True: Open browser-window.
False: Do not open browser-window.
- type showfig:
bool, (default: True)
- param overwrite:
True: Overwrite the html in the destination directory.
False: Do not overwrite destination file but show warning instead.
- type overwrite:
bool, (default: True)
- param notebook:
True: Use IPython to show chart in notebook.
False: Do not use IPython.
- type notebook:
bool
- param save_button:
True: Save button is shown in the HTML to save the image in svg.
False: No save button is shown in the HTML.
- type save_button:
bool, (default: True)
- param reset_properties:
True: Reset the node_properties at each run.
False: Use the d3.node_properties()
- type reset_properties:
bool, (default: True)
- 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 %H:%M:%S', 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 %H:%M:%S')
>>> 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]