{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "considered-injection", "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 = Scatter(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": "resistant-attachment", "metadata": {}, "outputs": [], "source": [ "scatt.opacities = [0.3, 0.5, 1.]" ] }, { "cell_type": "code", "execution_count": null, "id": "korean-survivor", "metadata": {}, "outputs": [], "source": [ "scatt.colors = ['green', 'red', 'blue']" ] }, { "cell_type": "code", "execution_count": null, "id": "amazing-belarus", "metadata": {}, "outputs": [], "source": [ "scatt.y = -scatt.y" ] }, { "cell_type": "code", "execution_count": null, "id": "optional-addiction", "metadata": {}, "outputs": [], "source": [ "scatt.default_size = 70" ] }, { "cell_type": "code", "execution_count": null, "id": "chemical-running", "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": "related-lesbian", "metadata": {}, "outputs": [], "source": [ "scatt.marker = 'square'" ] }, { "cell_type": "code", "execution_count": null, "id": "amazing-owner", "metadata": {}, "outputs": [], "source": [ "scatt.stroke = 'black'" ] }, { "cell_type": "code", "execution_count": null, "id": "going-cylinder", "metadata": {}, "outputs": [], "source": [ "scatt.stroke = None" ] }, { "cell_type": "code", "execution_count": null, "id": "weird-surgeon", "metadata": {}, "outputs": [], "source": [ "scatt.fill = False" ] }, { "cell_type": "code", "execution_count": null, "id": "equivalent-mining", "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": "angry-consciousness", "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.2" } }, "nbformat": 4, "nbformat_minor": 5 }