|
343 | 343 | "metadata": {},
|
344 | 344 | "outputs": [],
|
345 | 345 | "source": [
|
346 |
| - "from bqplot import *\n", |
| 346 | + "from bqplot import (LinearScale, Scatter, Label, Axis, Figure, Lines)\n", |
| 347 | + "import numpy as np\n", |
347 | 348 | "\n",
|
348 | 349 | "size = 100\n",
|
349 | 350 | "np.random.seed(0)\n",
|
|
359 | 360 | "scat = Scatter(x=x_data[:10], y=y_data[:10], scales={'x': sc_x, 'y': sc_y}, default_colors=['blue'],\n",
|
360 | 361 | " enable_move=True)\n",
|
361 | 362 | "lin = Lines(scales={'x': sc_x, 'y': sc_y}, stroke_width=4, line_style='dashed', colors=['orange'])\n",
|
362 |
| - "m = Label(value='Mean is %s'%np.mean(scat.y))\n", |
| 363 | + "m = Label(x=[0.05], y=[0.9], text=[\"\"], colors=[\"black\"])\n", |
363 | 364 | "\n",
|
364 | 365 | "def update_line(change):\n",
|
365 | 366 | " with lin.hold_sync():\n",
|
366 | 367 | " lin.x = [np.min(scat.x), np.max(scat.x)]\n",
|
367 | 368 | " lin.y = [np.mean(scat.y), np.mean(scat.y)]\n",
|
368 |
| - " m.value='Mean is %s'%np.mean(scat.y)\n", |
| 369 | + " m.text=['Mean is %s'%np.mean(scat.y)]\n", |
369 | 370 | " \n",
|
370 | 371 | "\n",
|
371 | 372 | "update_line(None)\n",
|
|
377 | 378 | "ax_x = Axis(scale=sc_x)\n",
|
378 | 379 | "ax_y = Axis(scale=sc_y, tick_format='0.2f', orientation='vertical')\n",
|
379 | 380 | "\n",
|
380 |
| - "fig = Figure(marks=[scat, lin], axes=[ax_x, ax_y])\n", |
| 381 | + "fig = Figure(marks=[scat, lin, m], axes=[ax_x, ax_y])\n", |
381 | 382 | "\n",
|
382 | 383 | "## In this case on drag, the line updates as you move the points.\n",
|
383 | 384 | "with scat.hold_sync():\n",
|
384 | 385 | " scat.enable_move = True\n",
|
385 | 386 | " scat.update_on_move = True\n",
|
386 | 387 | " scat.enable_add = False\n",
|
387 | 388 | "\n",
|
388 |
| - "display(m, fig)" |
| 389 | + "display(fig)" |
389 | 390 | ]
|
390 | 391 | },
|
391 | 392 | {
|
|
0 commit comments