Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
polakowo
GitHub Repository: polakowo/vectorbt
Path: blob/master/tests/notebooks/plotting.ipynb
1073 views
Kernel: Python 3 (ipykernel)

plotting

import vectorbt as vbt
import numpy as np import pandas as pd from datetime import datetime from numba import njit import itertools import ipywidgets
big_df = pd.DataFrame(np.random.uniform(size=(100, 100)).astype(float)) big_df.columns = list(map(str, big_df.columns)) print(big_df.shape)
(100, 100)

Indicator

gauge = vbt.plotting.Gauge(value=0, value_range=(-1, 1)) gauge.fig
FigureWidget({ 'data': [{'domain': {'x': [0, 1], 'y': [0, 1]}, 'gauge': {'axis': {'range': […
gauge.update(1)
%timeit vbt.plotting.Gauge(value=0) big_gauge = vbt.plotting.Gauge(value=0) %timeit big_gauge.update(0)
172 ms ± 1.65 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 468 µs ± 862 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
ipywidgets.Widget.close_all()

Bar

bar = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['a', 'b']).vbt.barplot(return_fig=False) bar.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'bar', …
bar.update([[7, 8], [9, 10], [11, 12]])
bar1 = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['a', 'b']).vbt.barplot(return_fig=False) bar2 = pd.DataFrame([[7, 8], [9, 10], [11, 12]], columns=['c', 'd']).vbt.barplot(return_fig=False, fig=bar1.fig) bar2.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'bar', …
bar1.update([[7, 8], [9, 10], [11, 12]])
bar2.update([[1, 2], [3, 4], [5, 6]])
%timeit pd.DataFrame(big_df).vbt.barplot() big_bar = pd.DataFrame(big_df).vbt.barplot(return_fig=False) %timeit big_bar.update(big_df.values * 2)
IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs)
350 ms ± 36.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 4.05 ms ± 17.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
ipywidgets.Widget.close_all()

Scatter

scatter = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['a', 'b']).vbt.plot(return_fig=False) scatter.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'scatter', …
scatter.update([[6, 5], [4, 3], [2, 1]])
scatter1 = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['a', 'b']).vbt.plot(return_fig=False) scatter2 = pd.DataFrame([[7, 8], [9, 10], [11, 12]], columns=['c', 'd']).vbt.plot(return_fig=False, fig=scatter1.fig) scatter2.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'scatter', …
scatter1.update([[7, 8], [9, 10], [11, 12]])
scatter2.update([[1, 2], [3, 4], [5, 6]])
%timeit pd.DataFrame(big_df).vbt.plot() big_scatter = pd.DataFrame(big_df).vbt.plot(return_fig=False) %timeit big_scatter.update(big_df.values * 2)
IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs)
2.34 ms ± 48.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
ipywidgets.Widget.close_all()

Histogram

hist = pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.histplot(return_fig=False) hist.fig
FigureWidget({ 'data': [{'name': 'a', 'opacity': 0.75, 'showlegend': True, …
hist.update([[4, 9], [4, 5], [3, 0]])
pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.histplot(horizontal=True)
FigureWidget({ 'data': [{'name': 'a', 'opacity': 0.75, 'showlegend': True, …
hist1 = pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.histplot(return_fig=False) hist2 = pd.DataFrame([[4, 9], [4, 5], [3, 0]], columns=['c', 'd']).vbt.histplot(return_fig=False, fig=hist1.fig) hist2.fig
FigureWidget({ 'data': [{'name': 'a', 'opacity': 0.75, 'showlegend': True, …
hist1.update([[4, 9], [4, 5], [3, 0]])
hist2.update([[1, 2], [3, 4], [2, 1]])
%timeit pd.DataFrame(big_df).vbt.histplot() big_hist = pd.DataFrame(big_df).vbt.histplot(return_fig=False) %timeit big_hist.update(big_df.values * 2)
IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs)
331 ms ± 24.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 4.32 ms ± 43.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
ipywidgets.Widget.close_all()

Box

box = pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.boxplot(return_fig=False) box.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'box', …
box.update([[4, 9], [4, 5], [3, 0]])
pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.boxplot(horizontal=True)
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'box', …
box1 = pd.DataFrame([[1, 2], [3, 4], [2, 1]], columns=['a', 'b']).vbt.boxplot(return_fig=False) box2 = pd.DataFrame([[4, 9], [4, 5], [3, 0]], columns=['c', 'd']).vbt.boxplot(return_fig=False, fig=box1.fig) box2.fig
FigureWidget({ 'data': [{'name': 'a', 'showlegend': True, 'type': 'box', …
box1.update([[4, 9], [4, 5], [3, 0]])
box2.update([[1, 2], [3, 4], [2, 1]])
%timeit pd.DataFrame(big_df).vbt.boxplot() big_box = pd.DataFrame(big_df).vbt.boxplot(return_fig=False) %timeit big_box.update(big_df.values * 2)
IOPub message rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_msg_rate_limit`. Current values: NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec) NotebookApp.rate_limit_window=3.0 (secs)
329 ms ± 25.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 4.29 ms ± 36.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
ipywidgets.Widget.close_all()

Heatmap

heatmap = pd.DataFrame( [[1, 2], [3, 4], [5, 6]], columns=['a', 'b'], index=['x', 'y', 'z'] ).vbt.heatmap(return_fig=False) heatmap.fig
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
heatmap.update([[6, 5], [4, 3], [2, 1]])
pd.DataFrame( [[1, 2], [3, 4], [5, 6]], columns=['a', 'b'], index=['x', 'y', 'z'] ).vbt.ts_heatmap()
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
heatmap1 = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['a', 'b'], index=['x', 'y', 'z']).vbt.heatmap( return_fig=False, trace_kwargs=dict(showscale=False)) heatmap2 = pd.DataFrame([[6, 5], [4, 3], [2, 1]], columns=['c', 'd'], index=['x2', 'y2', 'z2']).vbt.heatmap( return_fig=False, fig=heatmap1.fig) heatmap2.fig
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
heatmap1.update([[6, 5], [4, 3], [2, 1]])
heatmap2.update([[1, 2], [3, 4], [5, 6]])
heatmap_sr = pd.Series( [1, 2, 3, 6, 5, 4], index=vbt.base.index_fns.stack_indexes([ pd.Index(['i1', 'i2', 'i3', 'i1', 'i2', 'i3'], name='first'), pd.Index(['i4', 'i5', 'i6', 'i4', 'i5', 'i6'], name='second'), pd.Index(['i7', 'i7', 'i7', 'i8', 'i8', 'i8'], name='third') ]) ) heatmap_sr.vbt.heatmap(x_level=0, y_level=1, symmetric=True)
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
heatmap_sr.vbt.heatmap(x_level=0, y_level=1, symmetric=True, slider_level=2)
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
%timeit pd.DataFrame(big_df).vbt.heatmap() big_heatmap = pd.DataFrame(big_df).vbt.heatmap(return_fig=False) %timeit big_heatmap.update(big_df.values * 2)
427 ms ± 53.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 112 µs ± 7.16 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
ipywidgets.Widget.close_all()

Volume

x, y, z, g = np.mgrid[0:15, 15:25, 25:30, :2] volume_sr = pd.Series( np.random.randint(1, 10, size=x.flatten().shape), index=vbt.base.index_fns.stack_indexes([ pd.Index(x.flatten(), name='first'), pd.Index(y.flatten(), name='second'), pd.Index(z.flatten(), name='third'), pd.Index(g.flatten(), name='fourth') ]) ) volume = volume_sr.vbt.volume(x_level='first', y_level='second', z_level='third', return_fig=False) volume.fig
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
volume.update(np.random.randint(1, 10, size=x.flatten().shape))
volume_sr.vbt.volume(x_level='first', y_level='second', z_level='third', slider_level='fourth')
FigureWidget({ 'data': [{'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'], …
x, y, z = np.mgrid[:50, :50, :50] big_volume_sr = pd.Series( np.random.randint(1, 10, size=x.flatten().shape), index=vbt.base.index_fns.stack_indexes( pd.Index(x.flatten(), name='i1'), pd.Index(y.flatten(), name='i2'), pd.Index(z.flatten(), name='i3') ) ) %timeit big_volume_sr.vbt.volume() big_volume = big_volume_sr.vbt.volume(return_fig=False) %timeit big_volume.update(big_volume_sr.values * 2)
1.33 s ± 96.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) 822 µs ± 478 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
ipywidgets.Widget.close_all()