Debian Codegraph @

bqplot/examples/Marks/Pyplot/Label.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import numpy as np\n",
10 "import pandas as pd\n",
11 "\n",
12 "import bqplot.pyplot as plt"
13 ]
14 },
15 {
16 "cell_type": "code",
17 "execution_count": 2,
18 "metadata": {},
19 "outputs": [],
20 "source": [
21 "np.random.seed(10)\n",
22 "price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[0.5, 0.8], [0.8, 1.0]]), axis=0) + 100,\n",
23 " columns=['Security 1', 'Security 2'],\n",
24 " index=pd.date_range(start='01-01-2007', periods=150))\n",
25 "y_data = np.cumsum(np.random.randn(100))"
26 ]
27 },
28 {
29 "cell_type": "markdown",
30 "metadata": {},
31 "source": [
32 "## Label positioned in data coordinates"
33 ]
34 },
35 {
36 "cell_type": "code",
37 "execution_count": 3,
38 "metadata": {},
39 "outputs": [
40 {
41 "data": {
42 "application/vnd.jupyter.widget-view+json": {
43 "model_id": "475580d8a2fd4739bc8681e199937d3e",
44 "version_major": 2,
45 "version_minor": 0
46 },
47 "text/plain": [
48 "Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
49 ]
50 },
51 "metadata": {},
52 "output_type": "display_data"
53 }
54 ],
55 "source": [
56 "fig = plt.figure(title='Basic Label Example')\n",
57 "test_line = plt.plot(np.arange(10), y_data[:10])\n",
58 "test_label = plt.label(['Test', 'Label', 'for', 'the', 'Data'], \n",
59 " x=np.arange(5), y=y_data[:5], \n",
60 " default_size=26, font_weight='bolder',\n",
61 " colors=['orange', 'red'], update_on_move=True)\n",
62 "fig"
63 ]
64 },
65 {
66 "cell_type": "markdown",
67 "metadata": {},
68 "source": [
69 "Setting the label attribute `enable_move` to `True` makes the label draggable"
70 ]
71 },
72 {
73 "cell_type": "code",
74 "execution_count": 4,
75 "metadata": {},
76 "outputs": [],
77 "source": [
78 "# now the labels can be moved by dragging them!\n",
79 "test_label.enable_move = True"
80 ]
81 },
82 {
83 "cell_type": "markdown",
84 "metadata": {},
85 "source": [
86 "## Label positioned in terms of Figure coordinates"
87 ]
88 },
89 {
90 "cell_type": "code",
91 "execution_count": 5,
92 "metadata": {},
93 "outputs": [
94 {
95 "data": {
96 "application/vnd.jupyter.widget-view+json": {
97 "model_id": "b28c4173135b48b19f21b455b07edad6",
98 "version_major": 2,
99 "version_minor": 0
100 },
101 "text/plain": [
102 "Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
103 ]
104 },
105 "metadata": {},
106 "output_type": "display_data"
107 }
108 ],
109 "source": [
110 "fig = plt.figure()\n",
111 "\n",
112 "test_line = plt.plot(np.arange(10), y_data)\n",
113 "test_label = plt.label(['Test Label'], default_size=26, font_weight='bolder', colors=['orange'])\n",
114 "test_label.x = [0.5]\n",
115 "test_label.y = [0.2]\n",
116 "fig"
117 ]
118 },
119 {
120 "cell_type": "code",
121 "execution_count": 6,
122 "metadata": {},
123 "outputs": [],
124 "source": [
125 "# Rotating the label\n",
126 "test_label.rotate_angle = 30"
127 ]
128 },
129 {
130 "cell_type": "markdown",
131 "metadata": {},
132 "source": [
133 "## Label positioned at a Date value"
134 ]
135 },
136 {
137 "cell_type": "code",
138 "execution_count": 7,
139 "metadata": {},
140 "outputs": [
141 {
142 "data": {
143 "application/vnd.jupyter.widget-view+json": {
144 "model_id": "e0c4dbf20b944b488a9e340801bd1bfd",
145 "version_major": 2,
146 "version_minor": 0
147 },
148 "text/plain": [
149 "Figure(axes=[Axis(scale=DateScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top': 6…"
150 ]
151 },
152 "metadata": {},
153 "output_type": "display_data"
154 }
155 ],
156 "source": [
157 "fig = plt.figure()\n",
158 "lines = plt.plot(price_data.index, price_data['Security 1'])\n",
159 "label = plt.label(['Pi-Day'], x=[np.datetime64('2007-03-14')], colors=['orange'])\n",
160 "label.y = [.5]\n",
161 "fig"
162 ]
163 },
164 {
165 "cell_type": "code",
166 "execution_count": 8,
167 "metadata": {},
168 "outputs": [],
169 "source": [
170 "# Setting an offset in pixels\n",
171 "label.x_offset = 100"
172 ]
173 }
174 ],
175 "metadata": {
176 "anaconda-cloud": {},
177 "kernelspec": {
178 "display_name": "Python 3",
179 "language": "python",
180 "name": "python3"
181 },
182 "language_info": {
183 "codemirror_mode": {
184 "name": "ipython",
185 "version": 3
186 },
187 "file_extension": ".py",
188 "mimetype": "text/x-python",
189 "name": "python",
190 "nbconvert_exporter": "python",
191 "pygments_lexer": "ipython3",
192 "version": "3.7.6"
193 }
194 },
195 "nbformat": 4,
196 "nbformat_minor": 1
197 }