{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "faf6701a", "metadata": {}, "outputs": [], "source": [ "from bqplot import *\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "# Test data\n", "\n", "np.random.seed(0)\n", "price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[1.0, -0.8], [-0.8, 1.0]]), axis=0) + 100,\n", " columns=['Security 1', 'Security 2'], index=pd.date_range(start='01-01-2007', periods=150))\n", "size = 100\n", "x_data = range(size)\n", "y_data = np.cumsum(np.random.randn(size) * 100.0)\n", "ord_keys = np.array(['A', 'B', 'C', 'D', 'E', 'F'])\n", "ordinal_data = np.random.randint(5, size=size)\n", "\n", "symbols = ['Security 1', 'Security 2']\n", "\n", "dates_all = price_data.index.values\n", "dates_all_t = dates_all[1:]\n", "sec1_levels = np.array(price_data[symbols[0]].values.flatten())\n", "log_sec1 = np.log(sec1_levels)\n", "sec1_returns = log_sec1[1:] - log_sec1[:-1]\n", "\n", "sec2_levels = np.array(price_data[symbols[1]].values.flatten())\n", "\n", "# First draw\n", "\n", "sc_x = DateScale()\n", "sc_y = LinearScale()\n", "\n", "scatt = ScatterGL(x=dates_all, y=sec2_levels, scales={'x': sc_x, 'y': sc_y})\n", "ax_x = Axis(scale=sc_x, label='Date')\n", "ax_y = Axis(scale=sc_y, orientation='vertical', tick_format='0.0f', label='Security 2')\n", "\n", "fig = Figure(marks=[scatt], axes=[ax_x, ax_y])\n", "fig" ] }, { "cell_type": "code", "execution_count": null, "id": "3712536e", "metadata": {}, "outputs": [], "source": [ "scatt.opacities = [0.3, 0.5, 1.]" ] }, { "cell_type": "code", "execution_count": null, "id": "ade1421e", "metadata": {}, "outputs": [], "source": [ "scatt.colors = ['green', 'red', 'blue']" ] }, { "cell_type": "code", "execution_count": null, "id": "46db1d61", "metadata": {}, "outputs": [], "source": [ "# Doesn't work?\n", "# scatt.y = -scatt.y" ] }, { "cell_type": "code", "execution_count": null, "id": "4551a614", "metadata": {}, "outputs": [], "source": [ "# Doesn't work?\n", "# scatt.default_size = 70" ] }, { "cell_type": "code", "execution_count": null, "id": "3717a327", "metadata": {}, "outputs": [], "source": [ "scatt.scales = dict(x=sc_x, y=sc_y, color=ColorScale())\n", "scatt.color = scatt.y" ] }, { "cell_type": "code", "execution_count": null, "id": "6b814151", "metadata": {}, "outputs": [], "source": [ "scatt.marker = 'square'" ] }, { "cell_type": "code", "execution_count": null, "id": "b9783dc7", "metadata": {}, "outputs": [], "source": [ "scatt.stroke = 'black'" ] }, { "cell_type": "code", "execution_count": null, "id": "77a44842", "metadata": {}, "outputs": [], "source": [ "scatt.stroke = None" ] }, { "cell_type": "code", "execution_count": null, "id": "93564933", "metadata": {}, "outputs": [], "source": [ "scatt.fill = False" ] }, { "cell_type": "code", "execution_count": null, "id": "d43d838a", "metadata": {}, "outputs": [], "source": [ "scatt.fill = True" ] }, { "cell_type": "code", "execution_count": null, "id": "74371328", "metadata": {}, "outputs": [], "source": [ "scatt.selected_style = dict(fill='green')\n", "scatt.unselected_style = dict(fill='red')\n", "scatt.selected = list(range(50, 60))" ] }, { "cell_type": "code", "execution_count": null, "id": "a4e5f639", "metadata": {}, "outputs": [], "source": [ "scatt.selected = None" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 5 }