|
491 | 491 | "By default, the ScaleBar uses metric length units, but you can define custom units of measurement using the `CustomDimensional` model. This allows you to create scale bars with units such as angular measurements or any other custom units you might need. To learn more about customizing units and other advanced features of the ScaleBar, refer to the [Bokeh User Guide on Annotations](https://docs.bokeh.org/en/latest/docs/user_guide/basic/annotations.html#scale-bars)." |
492 | 492 | ] |
493 | 493 | }, |
| 494 | + { |
| 495 | + "cell_type": "markdown", |
| 496 | + "metadata": {}, |
| 497 | + "source": [ |
| 498 | + "### LaTeX" |
| 499 | + ] |
| 500 | + }, |
| 501 | + { |
| 502 | + "cell_type": "markdown", |
| 503 | + "metadata": {}, |
| 504 | + "source": [ |
| 505 | + "Bokeh supports LaTeX equations in a number of different elements.\n", |
| 506 | + "\n", |
| 507 | + "This is based on the [Bessel equation example](https://docs.bokeh.org/en/latest/docs/examples/styling/mathtext/latex_bessel.html) in the Bokeh documentation:" |
| 508 | + ] |
| 509 | + }, |
| 510 | + { |
| 511 | + "cell_type": "code", |
| 512 | + "execution_count": null, |
| 513 | + "metadata": {}, |
| 514 | + "outputs": [], |
| 515 | + "source": [ |
| 516 | + "# from bokeh.io import output_notebook\n", |
| 517 | + "# from bokeh.models import ColorBar, CustomJS, Div, FixedTicker, Label, LinearColorMapper, Paragraph, Slider\n", |
| 518 | + "from bokeh.palettes import TolPRGn, PiYG\n", |
| 519 | + "# from bokeh.plotting import column, figure, show\n", |
| 520 | + "import numpy as np\n", |
| 521 | + "from scipy.special import jv" |
| 522 | + ] |
| 523 | + }, |
| 524 | + { |
| 525 | + "cell_type": "code", |
| 526 | + "execution_count": null, |
| 527 | + "metadata": {}, |
| 528 | + "outputs": [], |
| 529 | + "source": [ |
| 530 | + "p = figure(\n", |
| 531 | + " width=700, height=450,\n", |
| 532 | + " title=r\"$$\\text{Bessel functions of the first kind: } J_\\alpha(x) = \\sum_{m=0}^{\\infty}\"\n", |
| 533 | + " r\"\\frac{(-1)^m}{m!\\:\\Gamma(m+\\alpha+1)} \\left(\\frac{x}{2}\\right)^{2m+\\alpha}$$\",\n", |
| 534 | + ")\n", |
| 535 | + "p.x_range.range_padding = 0\n", |
| 536 | + "p.xaxis.axis_label = r\"$$x$$\"\n", |
| 537 | + "p.yaxis.axis_label = r\"$$J_\\alpha(x)$$\"\n", |
| 538 | + "p.title.text_font_size = \"14px\"\n", |
| 539 | + "\n", |
| 540 | + "x = np.linspace(0.0, 14.0, 100)\n", |
| 541 | + "\n", |
| 542 | + "for i, (xlabel, ylabel) in enumerate(zip([0.5, 1.6, 2.8, 4.2], [0.95, 0.6, 0.5, 0.45])):\n", |
| 543 | + " p.line(x, jv(i, x), line_width=3, color=PiYG[4][i])\n", |
| 544 | + " p.add_layout(Label(text=r\"$$J_\" + str(i) + \"(x)$$\", x=xlabel, y=ylabel))\n", |
| 545 | + "\n", |
| 546 | + "show(p)" |
| 547 | + ] |
| 548 | + }, |
| 549 | + { |
| 550 | + "cell_type": "markdown", |
| 551 | + "metadata": {}, |
| 552 | + "source": [ |
| 553 | + "Note:\n", |
| 554 | + "\n", |
| 555 | + "- Use of standard LaTeX delimeters of ``$$``. Other options are available.\n", |
| 556 | + "- Use raw Python strings e.g. ``r\"$$\\alpha$$\"`` so that backslashes are interpreted as normal characters rather than control sequences. \n", |
| 557 | + "- ``Div`` and ``Paragraph`` accept LaTeX for just part of their contents, but for all other elements the whole contents must be LaTeX.\n", |
| 558 | + " - To put normal text in a LaTeX string use ``\\text{...}``.\n", |
| 559 | + " - We are actively working on improvements in this area.\n", |
| 560 | + "\n", |
| 561 | + "\n", |
| 562 | + "#### Where can LaTeX be used?" |
| 563 | + ] |
| 564 | + }, |
| 565 | + { |
| 566 | + "cell_type": "code", |
| 567 | + "execution_count": null, |
| 568 | + "metadata": {}, |
| 569 | + "outputs": [], |
| 570 | + "source": [ |
| 571 | + "from bokeh.models import ColorBar, Div, FixedTicker, LinearColorMapper, Paragraph, Slider\n", |
| 572 | + "from bokeh.plotting import column" |
| 573 | + ] |
| 574 | + }, |
| 575 | + { |
| 576 | + "cell_type": "code", |
| 577 | + "execution_count": null, |
| 578 | + "metadata": {}, |
| 579 | + "outputs": [], |
| 580 | + "source": [ |
| 581 | + "p = figure(width=500, height=400)\n", |
| 582 | + "p.scatter(1, 1, size=0)\n", |
| 583 | + "\n", |
| 584 | + "p.title = r\"$$\\LaTeX \\text{ figure title}$$\"\n", |
| 585 | + "p.axis.axis_label = r\"$$\\LaTeX \\text{ axis label}$$\"\n", |
| 586 | + "p.axis.ticker = FixedTicker(ticks=[1])\n", |
| 587 | + "p.axis.major_label_overrides = {1: r\"$$\\LaTeX \\text{ tick label}$$\"}\n", |
| 588 | + "p.yaxis.major_label_orientation = \"vertical\"\n", |
| 589 | + "p.add_layout(Label(text=r\"$$\\LaTeX \\text{ label}$$\", text_font_size=\"26px\",\n", |
| 590 | + " angle=0.4, text_baseline=\"middle\", text_align=\"center\", x=1, y=1))\n", |
| 591 | + "\n", |
| 592 | + "slider = Slider(start=0, end=100, value=50, step=1, title=r\"$$\\LaTeX \\text{ slider}$$\")\n", |
| 593 | + "div = Div(text=r\"$$\\LaTeX$$ div\")\n", |
| 594 | + "paragraph = Paragraph(text=r\"$$\\LaTeX$$ paragraph\")\n", |
| 595 | + "\n", |
| 596 | + "color_mapper = LinearColorMapper(palette=PiYG[8])\n", |
| 597 | + "colorbar = ColorBar(color_mapper=color_mapper, title=r\"$$\\LaTeX \\text{ colorbar title}$$\")\n", |
| 598 | + "p.add_layout(colorbar, \"right\")\n", |
| 599 | + "\n", |
| 600 | + "show(column(p, slider, div, paragraph))" |
| 601 | + ] |
| 602 | + }, |
| 603 | + { |
| 604 | + "cell_type": "markdown", |
| 605 | + "metadata": {}, |
| 606 | + "source": [ |
| 607 | + "For further information see the [LaTeX section](https://docs.bokeh.org/en/latest/docs/user_guide/styling/mathtext.html#latex) in the User Guide." |
| 608 | + ] |
| 609 | + }, |
494 | 610 | { |
495 | 611 | "cell_type": "markdown", |
496 | 612 | "metadata": {}, |
|
0 commit comments