{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "import bqplot.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "np.random.seed(10)\n", "price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[0.5, 0.8], [0.8, 1.0]]), axis=0) + 100,\n", " columns=['Security 1', 'Security 2'],\n", " index=pd.date_range(start='01-01-2007', periods=150))\n", "y_data = np.cumsum(np.random.randn(100))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Label positioned in data coordinates" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "475580d8a2fd4739bc8681e199937d3e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = plt.figure(title='Basic Label Example')\n", "test_line = plt.plot(np.arange(10), y_data[:10])\n", "test_label = plt.label(['Test', 'Label', 'for', 'the', 'Data'], \n", " x=np.arange(5), y=y_data[:5], \n", " default_size=26, font_weight='bolder',\n", " colors=['orange', 'red'], update_on_move=True)\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Setting the label attribute `enable_move` to `True` makes the label draggable" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# now the labels can be moved by dragging them!\n", "test_label.enable_move = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Label positioned in terms of Figure coordinates" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b28c4173135b48b19f21b455b07edad6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = plt.figure()\n", "\n", "test_line = plt.plot(np.arange(10), y_data)\n", "test_label = plt.label(['Test Label'], default_size=26, font_weight='bolder', colors=['orange'])\n", "test_label.x = [0.5]\n", "test_label.y = [0.2]\n", "fig" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Rotating the label\n", "test_label.rotate_angle = 30" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Label positioned at a Date value" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e0c4dbf20b944b488a9e340801bd1bfd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(scale=DateScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top': 6…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = plt.figure()\n", "lines = plt.plot(price_data.index, price_data['Security 1'])\n", "label = plt.label(['Pi-Day'], x=[np.datetime64('2007-03-14')], colors=['orange'])\n", "label.y = [.5]\n", "fig" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Setting an offset in pixels\n", "label.x_offset = 100" ] } ], "metadata": { "anaconda-cloud": {}, "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.7.6" } }, "nbformat": 4, "nbformat_minor": 1 }