| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"metadata": { |
| 7 |
"scrolled": true |
| 8 |
}, |
| 9 |
"outputs": [], |
| 10 |
"source": [ |
| 11 |
"from bqplot import (DateScale, LinearScale, ColorScale, \n", |
| 12 |
" Axis, ColorAxis, Figure, FlexLine)\n", |
| 13 |
"import numpy as np" |
| 14 |
] |
| 15 |
}, |
| 16 |
{ |
| 17 |
"cell_type": "markdown", |
| 18 |
"metadata": {}, |
| 19 |
"source": [ |
| 20 |
"## Get Data" |
| 21 |
] |
| 22 |
}, |
| 23 |
{ |
| 24 |
"cell_type": "code", |
| 25 |
"execution_count": null, |
| 26 |
"metadata": { |
| 27 |
"scrolled": true |
| 28 |
}, |
| 29 |
"outputs": [], |
| 30 |
"source": [ |
| 31 |
"dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\n", |
| 32 |
"size = len(dates)\n", |
| 33 |
"spx = 100 + 5 * np.cumsum(np.random.randn(size))\n", |
| 34 |
"vix = 10 + np.cumsum(np.random.randn(size))" |
| 35 |
] |
| 36 |
}, |
| 37 |
{ |
| 38 |
"cell_type": "markdown", |
| 39 |
"metadata": {}, |
| 40 |
"source": [ |
| 41 |
"## Displaying extra dimension with color" |
| 42 |
] |
| 43 |
}, |
| 44 |
{ |
| 45 |
"cell_type": "code", |
| 46 |
"execution_count": null, |
| 47 |
"metadata": { |
| 48 |
"scrolled": false |
| 49 |
}, |
| 50 |
"outputs": [], |
| 51 |
"source": [ |
| 52 |
"lin_x = DateScale()\n", |
| 53 |
"lin_y = LinearScale()\n", |
| 54 |
"col_line = ColorScale(colors=['green', 'white', 'red'])\n", |
| 55 |
"\n", |
| 56 |
"ax_x = Axis(scale=lin_x, label='Date', label_location='end')\n", |
| 57 |
"ax_y = Axis(scale=lin_y, orientation='vertical', label='Index', label_offset='4ex')\n", |
| 58 |
"ax_col = ColorAxis(label='Vol', scale=col_line, tick_format='0.2f')\n", |
| 59 |
"\n", |
| 60 |
"fig_margin = dict(top=50, left=80, right=20, bottom=70)\n", |
| 61 |
"fl = FlexLine(x=dates, y=spx, color=vix,\n", |
| 62 |
" scales={'x': lin_x, 'color': col_line, 'y': lin_y})\n", |
| 63 |
"\n", |
| 64 |
"Figure(marks=[fl], axes=[ax_x, ax_y, ax_col], fig_margin=fig_margin)" |
| 65 |
] |
| 66 |
}, |
| 67 |
{ |
| 68 |
"cell_type": "markdown", |
| 69 |
"metadata": {}, |
| 70 |
"source": [ |
| 71 |
"## Displaying extra dimension with width" |
| 72 |
] |
| 73 |
}, |
| 74 |
{ |
| 75 |
"cell_type": "code", |
| 76 |
"execution_count": null, |
| 77 |
"metadata": { |
| 78 |
"scrolled": false |
| 79 |
}, |
| 80 |
"outputs": [], |
| 81 |
"source": [ |
| 82 |
"lin_x = DateScale()\n", |
| 83 |
"lin_y = LinearScale()\n", |
| 84 |
"width_line = LinearScale()\n", |
| 85 |
"\n", |
| 86 |
"\n", |
| 87 |
"ax_x = Axis(scale=lin_x, label='Date')\n", |
| 88 |
"ax_y = Axis(scale=lin_y, orientation='vertical', label='SPX Index')\n", |
| 89 |
"\n", |
| 90 |
"fl2 = FlexLine(x=dates, y=spx, width=vix,\n", |
| 91 |
" scales={'x': lin_x, 'width': width_line, 'y': lin_y},\n", |
| 92 |
" stroke_width=5)\n", |
| 93 |
"\n", |
| 94 |
"Figure(marks=[fl2], axes=[ax_x, ax_y])" |
| 95 |
] |
| 96 |
} |
| 97 |
], |
| 98 |
"metadata": { |
| 99 |
"kernelspec": { |
| 100 |
"display_name": "Python 3", |
| 101 |
"language": "python", |
| 102 |
"name": "python3" |
| 103 |
}, |
| 104 |
"language_info": { |
| 105 |
"codemirror_mode": { |
| 106 |
"name": "ipython", |
| 107 |
"version": 3 |
| 108 |
}, |
| 109 |
"file_extension": ".py", |
| 110 |
"mimetype": "text/x-python", |
| 111 |
"name": "python", |
| 112 |
"nbconvert_exporter": "python", |
| 113 |
"pygments_lexer": "ipython3", |
| 114 |
"version": "3.7.6" |
| 115 |
} |
| 116 |
}, |
| 117 |
"nbformat": 4, |
| 118 |
"nbformat_minor": 1 |
| 119 |
} |