{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "af595ff1", "metadata": {}, "outputs": [], "source": [ "from bqplot import *\n", "import numpy as np\n", "\n", "price_data1 = [['2015-01-02 00:00:00', [161.31, 163.31, 161.0, 162.06]],\n", " ['2015-01-05 00:00:00', [161.27, 161.27, 159.19, 159.51]],\n", " ['2015-01-06 00:00:00', [159.67, 159.96, 155.17, 156.07]],\n", " ['2015-01-07 00:00:00', [157.2, 157.2, 154.03, 155.05]],\n", " ['2015-01-08 00:00:00', [156.24, 159.044, 155.55, 158.42]],\n", " ['2015-01-09 00:00:00', [158.42, 160.34, 157.25, 159.11]],\n", " ['2015-01-12 00:00:00', [159.0, 159.25, 155.76, 156.44]],\n", " ['2015-01-13 00:00:00', [157.26, 159.97, 155.68, 156.81]],\n", " ['2015-01-14 00:00:00', [154.86, 156.49, 153.74, 155.8]],\n", " ['2015-01-15 00:00:00', [156.69, 156.97, 154.16, 154.57]]]\n", "\n", "price_data2 = [['2015-01-02 00:00:00', [111.39, 111.44, 107.35, 109.33]],\n", " ['2015-01-05 00:00:00', [108.29, 108.65, 105.41, 106.25]],\n", " ['2015-01-06 00:00:00', [106.54, 107.43, 104.63, 106.26]],\n", " ['2015-01-07 00:00:00', [107.2, 108.2, 106.695, 107.75]],\n", " ['2015-01-08 00:00:00', [109.23, 112.15, 108.7, 111.89]],\n", " ['2015-01-09 00:00:00', [112.67, 113.25, 110.21, 112.01]],\n", " ['2015-01-12 00:00:00', [112.6, 112.63, 108.8, 109.25]],\n", " ['2015-01-13 00:00:00', [111.43, 112.8, 108.91, 110.22]],\n", " ['2015-01-14 00:00:00', [109.04, 110.49, 108.5, 109.8]],\n", " ['2015-01-15 00:00:00', [110.0, 110.06, 106.66, 106.82]]]\n", "\n", "from bqplot.traits import convert_to_date\n", "\n", "dates1 = convert_to_date([d[0] for d in price_data1])\n", "prices1 = [d[1] for d in price_data1]\n", "\n", "dates2 = convert_to_date([d[0] for d in price_data2])\n", "prices2 = [d[1] for d in price_data2]\n", "\n", "sc_y = LinearScale()\n", "sc_x = LinearScale()\n", "\n", "ax_x = Axis(label='X', scale=sc_x)\n", "ax_y = Axis(label='Y', scale=sc_y, orientation='vertical', tick_format='0.2f')\n", "\n", "ohlc = OHLC(x=np.arange(len(dates2)) + 1, y=np.array(prices2) / 60,\n", " marker='bar', scales={'x': sc_x, 'y': sc_y}, colors=['dodgerblue','orange'])\n", "\n", "Figure(axes=[ax_x, ax_y], marks=[ohlc])" ] }, { "cell_type": "code", "execution_count": null, "id": "e65e1273", "metadata": {}, "outputs": [], "source": [ "ohlc.marker = 'candle'" ] }, { "cell_type": "code", "execution_count": null, "id": "a5b90e65", "metadata": {}, "outputs": [], "source": [ "ohlc.colors = ['green', 'red']" ] }, { "cell_type": "code", "execution_count": null, "id": "254b3eb4", "metadata": {}, "outputs": [], "source": [ "ohlc.opacities = [0.5, 0.5, 0.5, 0.2]" ] }, { "cell_type": "code", "execution_count": null, "id": "9c3cfbac", "metadata": {}, "outputs": [], "source": [ "# Doesn't work?\n", "# ohlc.format = 'hl'" ] }, { "cell_type": "code", "execution_count": null, "id": "981636d4", "metadata": {}, "outputs": [], "source": [ "ohlc.stroke = 'green'" ] }, { "cell_type": "code", "execution_count": null, "id": "ab3c0eaa", "metadata": {}, "outputs": [], "source": [ "ohlc.stroke_width = 3" ] }, { "cell_type": "code", "execution_count": null, "id": "3b80b31f", "metadata": {}, "outputs": [], "source": [ "ohlc.x = - ohlc.x" ] }, { "cell_type": "code", "execution_count": null, "id": "50a900b0", "metadata": {}, "outputs": [], "source": [ "ohlc.y = 2 * ohlc.y" ] }, { "cell_type": "code", "execution_count": null, "id": "7f8af7f4", "metadata": {}, "outputs": [], "source": [ "# Doesn't work?\n", "\n", "# ohlc.selected_style = {'fill': 'blue'}\n", "# ohlc.selected = [0, 2, 5]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 5 }