{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "531b2116-7af8-450c-88db-bb3257b2e596", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Copy button is now ENABLED.\n" ] } ], "source": [ "%toggle_copy_spec_button on" ] }, { "cell_type": "markdown", "id": "0a47783b-bc0d-47d8-9955-797abb2c0da5", "metadata": {}, "source": [ "# LaTeX" ] }, { "cell_type": "code", "execution_count": 2, "id": "82725896-3714-4a2d-978d-f9c3f08b746a", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 3, "id": "f09caf45-61ae-47f9-a9b5-6618b58d641e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 4, "id": "f309984e-88db-4ddd-8f90-9edaeb315af4", "metadata": {}, "outputs": [], "source": [ "formulas = [\n", " r\"\\(a\\)\",\n", " r\"\\(a \\quad + \\: 1\\)\",\n", " r\"\\( \\alpha \\cdot b + \\gamma \\)\",\n", " r\"\\((a - b)(a + b)\\)\",\n", " r\"\\((a / (\\Delta / c))\\)\",\n", " r\"\\(2^3\\)\",\n", " r\"\\(\\Alpha + \\alpha^{\\Beta + \\beta^{\\Gamma + \\gamma_{\\Delta + \\delta + \\Delta} + \\Gamma} + \\Beta} + \\Alpha\\)\",\n", " r\"t\\(^2\\)\",\n", " r\"\\((\\eta + a^{d})(\\eta - a^d)\\)\",\n", " r\"\\(a_2 x^2\\)\",\n", " r\"\\(\\Alpha\\Beta_{\\gamma\\delta}\\Sigma^\\infty\\)\",\n", " r\"\\((1 + (a^2 + 2))(b^{2\\theta - 1} - (c^{-1} / \\chi_i))\\)\",\n", " r\"\\(\\frac{a}{b}\\)\",\n", " r\"\\(a + \\frac{b}{c}\\)\",\n", " r\"\\(\\frac{a}{b} + c\\)\",\n", " r\"\\(\\frac{a}{b} + \\frac{c}{d}\\)\",\n", " r\"\\(\\frac{a + b}{d} + \\frac{d}{e + f}\\)\",\n", " r\"\\(\\frac{a}{b + c} + \\frac{d + e}{f}\\)\",\n", " r\"\\(10^{1000} - \\frac{\\Alpha^\\beta - \\gamma_\\Delta}{\\Omega} - \\frac{\\omega}{\\alpha_\\Beta - \\Gamma^\\delta} - 1000^{10}\\)\",\n", " r\"\\(\\alpha^\\frac{a + b}{c} + \\beta_{\\frac{d}{e + f}}\\)\",\n", " r\"\\(A^{\\frac{a^2}{b_1 + c_1} + \\frac{d_1 + e_1}{f^2}} + \\frac{B + C^2}{D^2 + E}\\)\",\n", " r\"\\(1^{2^{\\frac{3^4 + 3}{3^4 + 3} + 3} + 2} + 1^{2^{\\frac{3^4 + 3}{3^4 + 3} + 3} + 2}\\)\",\n", " r\"ABC & \\(a + \\frac{b + c + d}{e} + f\\) & DEF\",\n", " r'GitHub & \\(a + \\frac{b + c + d}{e} + f\\) & GitHub',\n", "]\n", "additional_formulas = [\n", " r\"*Markdown* & \\(a + \\frac{b + c + d}{e} + f\\) & *Markdown*\",\n", " r\"**Markdown** & \\(a + \\frac{b + c + d}{e} + f\\) & **Markdown**\",\n", " r\"Markdown & \\(a + \\frac{b + c + d}{e} + f\\) & Markdown\",\n", " r\"\\(a + \\frac{b + c + d}{e} + f\\)\" + ' \\n' + r\"\\(a + \\frac{b + c + d}{e} + f\\)\",\n", "]" ] }, { "cell_type": "code", "execution_count": 5, "id": "9e89304b-9270-405c-bcdf-cfbe265da326", "metadata": {}, "outputs": [], "source": [ "def formula_to_plot1(formula, n=None, hjust=None, nudge_x=None, livemap=False):\n", " p = ggplot()\n", " if livemap:\n", " p += geom_livemap()\n", " p += geom_hline(yintercept=0, color=\"white\", tooltips='none') + \\\n", " geom_vline(xintercept=0, color=\"white\", tooltips='none') + \\\n", " geom_text(x=0, label=formula, size=10, color=\"blue\",\n", " hjust=hjust, nudge_x=nudge_x) + \\\n", " theme_void() + \\\n", " theme(plot_background=element_rect(fill=\"#eeeeee\", size=2),\n", " plot_title=element_markdown(size=10))\n", " if n is not None:\n", " latex = formula.replace(r\"\\(\", \"$\").replace(r\"\\)\", \"$\")\n", " p += ggtitle('**LaTeX #{0}:** \"{1}\"'.format(n, latex.replace(\"^\", r\"\\^\")))\n", " return p\n", "\n", "def formula_to_plot2(formula, n=None, hjust=None, nudge_x=None, livemap=False):\n", " p = ggplot()\n", " if livemap:\n", " p += geom_livemap()\n", " p += geom_hline(aes(yintercept=[0, -.25, .25]), color=\"white\", tooltips='none') + \\\n", " geom_vline(xintercept=0, color=\"white\", tooltips='none') + \\\n", " geom_text(x=0, label=formula, size=1, size_unit='y', color=\"blue\",\n", " hjust=hjust, nudge_x=nudge_x) + \\\n", " ylim(-.6, .6) + \\\n", " theme_void() + \\\n", " theme(plot_background=element_rect(fill=\"#eeeeee\", size=2),\n", " plot_title=element_markdown(size=10))\n", " if n is not None:\n", " latex = formula.replace(r\"\\(\", \"$\").replace(r\"\\)\", \"$\")\n", " p += ggtitle('**LaTeX #{0}:** \"{1}\"'.format(n, latex.replace(\"^\", r\"\\^\")))\n", " return p\n", "\n", "def formula_to_plot3(formula, n=None, hjust=None, **args):\n", " caption = None\n", " if n is not None:\n", " latex = formula.replace(r\"\\(\", \"$\").replace(r\"\\)\", \"$\")\n", " caption = '**LaTeX #{0}:** \"{1}\"'.format(n, latex.replace(\"^\", r\"\\^\"))\n", " return ggplot() + \\\n", " geom_point(x=0, color=\"rgba(0,0,0,0)\", tooltips='none') + \\\n", " theme_void() + \\\n", " labs(title=formula, caption=caption) + \\\n", " theme(plot_background=element_rect(fill=\"#eeeeee\", size=2),\n", " plot_title=element_markdown(size=20, margin=[20, 0, 0, 0], hjust=hjust, color=\"blue\"),\n", " plot_caption=element_markdown(hjust=0))\n", "\n", "def formulas_plot(plot_function, formulas_list=formulas, width=1000, height=1500, **args):\n", " return gggrid([\n", " plot_function(formula, n=i, **args)\n", " for i, formula in enumerate(formulas_list)\n", " ], ncol=2) + ggsize(width, height)" ] }, { "cell_type": "markdown", "id": "43b46a21-f52f-4c46-8bb4-01fcfacf3818", "metadata": {}, "source": [ "### Centered `hjust`" ] }, { "cell_type": "code", "execution_count": 6, "id": "30c24b13-c401-4860-9659-1472c08987c8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "