示例#1
0
 def test_with_INLINE_resources(self) -> None:
     from latex_label import LatexLabel
     plot = Plot()
     plot.add_layout(LatexLabel())
     bundle = beb.bundle_for_objs_and_resources([plot], "inline")
     assert len(bundle.js_raw) == 3
     assert "class LatexLabelView" in bundle.js_raw[2]
示例#2
0
 def test_with_CDN_resources(self) -> None:
     from latex_label import LatexLabel
     plot = Plot()
     plot.add_layout(LatexLabel())
     bundle = beb.bundle_for_objs_and_resources([plot], "cdn")
     assert len(bundle.js_files) == 2
     assert bundle.js_files[1] == "https://unpkg.com/latex_label@^0.0.1/dist/latex_label.js"
示例#3
0
 def test_with_Server_resources(self) -> None:
     from latex_label import LatexLabel
     plot = Plot()
     plot.add_layout(LatexLabel())
     bundle = beb.bundle_for_objs_and_resources([plot], "server")
     assert len(bundle.js_files) == 2
     assert bundle.js_files[1] == "http://localhost:5006/static/extensions/latex_label/latex_label.js"
示例#4
0
 def test_with_Server_resources_dev(self) -> None:
     from latex_label import LatexLabel
     plot = Plot()
     plot.add_layout(LatexLabel())
     with envset(BOKEH_RESOURCES="server", BOKEH_DEV="true"):
         bundle = beb.bundle_for_objs_and_resources([plot], "server")
     assert len(bundle.js_files) == 2
     assert bundle.js_files[1] == "http://localhost:5006/static/extensions/latex_label/latex_label.js"
示例#5
0
 def test_with_Server_resources(self) -> None:
     from latex_label import LatexLabel
     plot = Plot()
     plot.add_layout(LatexLabel())
     bundle = beb.bundle_for_objs_and_resources([plot], "server")
     version_hash = "6b13789e43e5485634533de16a65d8ba9d34c4c9758588b665805435f80eb115"
     assert len(bundle.js_files) == 2
     assert (bundle.js_files[1] ==
             f"http://localhost:5006/static/extensions/latex_label/latex_label.js?v={version_hash}")
示例#6
0
    def _setup_formulas(self):
        label = LatexLabel(self)
        label.latex_text = (r'$' +
                            r'B_W(E\lambda) = \left(\frac{1}{4\pi}\right)' +
                            r'\left[ \frac{3}{3+\lambda} \right]^2' +
                            r'(1.2A^{1/3})^{2\lambda}' +
                            r'e^2\ \mathrm{fm}^{2\lambda}' + r'$')
        fill_placeholder(self.ui.disp_b_e_lambda, label)

        label = LatexLabel(self)
        label.latex_text = (r'$' +
                            r'B_W(M\lambda) = \left(\frac{10}{\pi}\right)' +
                            r'\left[ \frac{3}{3+\lambda} \right]^2' +
                            r'(1.2A^{1/3})^{2\lambda - 2}' +
                            r'\mu_N^2\ \mathrm{fm}^{2\lambda - 2}' + r'$')
        fill_placeholder(self.ui.disp_b_m_lambda, label)

        lambd, A, e, fm, mu_N = sympy.symbols('lambda A e fm mu_N')
        one = sympy.S(1)
        pi = sympy.pi

        self.subs_elambda = LatexLabel(self)
        fill_placeholder(self.ui.disp_subs_elambda, self.subs_elambda)

        self.subs_all = LatexLabel(self)
        fill_placeholder(self.ui.disp_subs_all, self.subs_all)

        self.disp_e_fm = LatexLabel(self)
        fill_placeholder(self.ui.output_e_fm, self.disp_e_fm)

        self.disp_wu = LatexLabel(self)
        fill_placeholder(self.ui.output_wu, self.disp_wu)

        self.base_formula = {
            'E': (3 / (3 + lambd))**2 / (4 * pi) *
            (1.2 * A**(one / 3))**(2 * lambd) * e**2 * fm**(2 * lambd),
            'M': (3 / (3 + lambd))**2 * (10 / pi) *
            (1.2 * A**(one / 3))**(2 * lambd - 2) * mu_N**2 *
            fm**(2 * lambd - 2),
        }
示例#7
0
from latex_label import LatexLabel

build("latex_label")



output_file('latex_extension.html')

p = figure(title="LaTex Extension Demonstration", plot_width=800, plot_height=350,
           background_fill_color="#fafafa")
p.x_range.range_padding = 0

x = np.arange(0.0, 20.0, 0.02)

for i, n in enumerate([0, 1, 4, 7]):
    p.line(x, jv(n, x), line_width=3, color=Spectral4[i], alpha=0.8, legend_label="𝜈=%d" % n)

text = r"""
\text{Bessel Functions of the First Kind: }
J_\nu = \sum_{m=0}^{\infty}\frac{(-1)^m}{m!\ \Gamma(m+\nu+1)}
\left(\frac{x}{2}\right)^{2m+\nu}
"""

latex = LatexLabel(text=text, x=4.5, y=250,
                   x_units='data', y_units='screen',
                   render_mode='css', text_font_size='8pt',
                   background_fill_color="white", border_line_color="lightgrey")
p.add_layout(latex)

show(p)
示例#8
0
           background_fill_color="#fafafa")
p.x_range.range_padding = 0

x = np.arange(0.0, 20.0, 0.02)

for i, n in enumerate([0, 1, 4, 7]):
    p.line(x,
           jv(n, x),
           line_width=3,
           color=Spectral4[i],
           alpha=0.8,
           legend_label="𝜈=%d" % n)

text = r"""
\text{Bessel Functions of the First Kind: }
J_\nu = \sum_{m=0}^{\infty}\frac{(-1)^m}{m!\ \Gamma(m+\nu+1)}
\left(\frac{x}{2}\right)^{2m+\nu}
"""

latex = LatexLabel(text=text,
                   x=4.5,
                   y=250,
                   x_units='data',
                   y_units='screen',
                   render_mode='css',
                   text_font_size='11px',
                   border_line_color="lightgrey")
p.add_layout(latex)

show(p)
示例#9
0
import numpy as np

from bokeh.plotting import figure, show
from latex_label import LatexLabel

x = np.arange(0.0, 1.0 + 0.01, 0.01)
y = np.cos(2 * 2 * np.pi * x) + 2

p = figure(title="LaTex Demonstration", plot_width=500, plot_height=500)
p.line(x, y)

# Note: must set ``render_mode="css"``
latex = LatexLabel(text="f = \sum_{n=1}^\infty\\frac{-e^{i\pi}}{2^n}!",
                   x=40,
                   y=445,
                   x_units='screen',
                   y_units='screen',
                   render_mode='css',
                   text_font_size='16pt',
                   background_fill_alpha=0)

p.add_layout(latex)

show(p)