{ "cells": [ { "cell_type": "markdown", "id": "2bb8845e-5844-4cfa-b008-6a6b482391d8", "metadata": {}, "source": [ "# LaTeX Support\n", "\n", "Note that LaTeX formulas are not fully supported when exporting to PNG/PDF." ] }, { "cell_type": "code", "execution_count": 1, "id": "eee2a2ae-760f-4a14-a2a1-722be25d5020", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "cfc33c00-bca9-4b63-9b4a-e2712c7487c1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "4ca63004-e567-44d1-9a10-62505a37f51d", "metadata": {}, "source": [ "## Power Degree" ] }, { "cell_type": "code", "execution_count": 3, "id": "60b010a9-860c-4ec8-9b51-b704978f3666", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data1 = {'x': list(range(-10, 11))}\n", "ggplot() + \\\n", " geom_function(aes(x='x'), data=data1, fun=lambda x: x**3 - 100 * x) + \\\n", " ggtitle(\"Graph of the \\( y = x^3 - 100 x \\)\") + \\\n", " theme(text=element_text(family=\"Times New Roman\"), \\\n", " plot_title=element_text(size=20, face='bold'))" ] }, { "cell_type": "markdown", "id": "a9c7e104-640a-4fa0-b922-a1c22747151a", "metadata": {}, "source": [ "## Subscript" ] }, { "cell_type": "markdown", "id": "ab9ead5c-deec-4794-9ef6-01e6454e75f9", "metadata": {}, "source": [ "Dataset: [owid-co2-data.csv](https://github.com/owid/co2-data/blob/master/owid-co2-data.csv) © [Our World in Data](https://ourworldindata.org) ([Licensed under CC BY 4.0](https://creativecommons.org/licenses/by/4.0/))" ] }, { "cell_type": "code", "execution_count": 4, "id": "de9c75ad-44f4-458c-a3e8-f64be58f185b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw_df = pd.read_csv(\"https://raw.githubusercontent.com/owid/co2-data/refs/heads/master/owid-co2-data.csv\")\n", "df = raw_df[raw_df[\"country\"].isin([\"World\", \"United States\", \"United Kingdom\", \"China\", \"India\"])]\n", "\n", "ggplot(df, aes(\"year\", \"co2_per_capita\", color=\"country\")) + \\\n", " geom_line(tooltips=layer_tooltips().title(\"@year\\nin tonnes per person\").format(\"year\", \"d\")\n", " .line(\"@country: @co2_per_capita\").format(\"@co2_per_capita\", \"{.1f} t\")) + \\\n", " scale_x_continuous(name=\"\", format=\"d\") + \\\n", " scale_y_continuous(name=\"\", format=\"{d} t\", expand=[0, 0]) + \\\n", " ggtitle(\"\\( CO_2 \\) emissions\", \"[tonnes per capita]\") + \\\n", " ggsize(1000, 400) + \\\n", " theme(text=element_text(family=\"Playfair Display\"), \\\n", " plot_title=element_text(size=20, face='bold'),\n", " plot_subtitle=element_text(size=16))" ] }, { "cell_type": "markdown", "id": "1d8a27a3-63f9-43bf-9e5c-092235068bd7", "metadata": {}, "source": [ "## Greek Letters and Other Special Symbols" ] }, { "cell_type": "code", "execution_count": 5, "id": "c0cd2656-d5ec-41f2-b78c-be1ed3f53069", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + \\\n", " geom_text(x=0, label=r\"\\( e^{i \\cdot \\pi} = -1 \\)\", \\\n", " size=70, family=\"Computer Modern Math\", fontface='italic') + \\\n", " theme_void()" ] }, { "cell_type": "markdown", "id": "7be88175-d135-48f7-92f6-14a4e08a5df9", "metadata": {}, "source": [ "## Place Your Formulas Anywhere!" ] }, { "cell_type": "code", "execution_count": 6, "id": "9d234197-b825-44d9-aa2e-df4159b0fd2f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data2 = {\n", " \"x\": [r\"\\( \\Omega_{\\rho + 1} \\)\"],\n", " r\"\\(\\delta\\)\": [1],\n", " \"f\": [r\"\\( A \\neq B^2 \\)\"],\n", "}\n", "\n", "ggplot(data2) + \\\n", " geom_bar(aes(\"x\", r\"\\(\\delta\\)\", fill=\"x\"), stat='identity', \\\n", " labels=layer_labels().line(\"@f\"), \\\n", " tooltips=layer_tooltips().line(\"@f\")) + \\\n", " scale_fill_manual([\"#6a3d9a\"], name=r\"\\(\\Sigma\\)\") + \\\n", " xlab(r\"\\(\\sigma\\)\") + \\\n", " theme(label_text=element_text(size=20))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.20" } }, "nbformat": 4, "nbformat_minor": 5 }