{ "cells": [ { "cell_type": "markdown", "id": "b688f244-c275-48fa-a578-21f84a87e384", "metadata": {}, "source": [ "## Markdown support" ] }, { "cell_type": "code", "execution_count": 1, "id": "8f15dd53-32d7-402b-8d4e-d6f3267f3227", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "a58056ef-179d-4e66-bdd5-24d2836457b5", "metadata": {}, "outputs": [], "source": [ "p = ggplot() \\\n", " + geom_blank() \\\n", " + labs(title='*Hello*, **world**', subtitle='_Simple plot_', caption='*Powered by **lets-plot***', x='Title **X**', y='Title **Y**') \\\n", " + ggsize(400, 200)" ] }, { "cell_type": "markdown", "id": "cc5d32d7-574a-408e-999f-b4abb704a66f", "metadata": {}, "source": [ "#### With markdown disabled (default)" ] }, { "cell_type": "code", "execution_count": 3, "id": "6333bac4-f969-4294-8dfc-cffb671aa303", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p" ] }, { "cell_type": "markdown", "id": "7d6b5cad-44a2-47dc-a755-4a55a7fa6222", "metadata": {}, "source": [ "#### Titles with enabled Markdown" ] }, { "cell_type": "code", "execution_count": 4, "id": "7bc1a4e8-7808-4beb-b94a-72e79d21e757", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(title=element_markdown())" ] }, { "cell_type": "markdown", "id": "3ea2abdb-9176-4602-960a-d671370d9ec5", "metadata": {}, "source": [ "#### Theme parameteres like color and font size are applicable to markdown elements:" ] }, { "cell_type": "code", "execution_count": 5, "id": "70c1bb86-a05e-463c-b635-74a25c573681", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(\n", " title=element_markdown(),\n", " axis_title=element_markdown(color='red'),\n", " plot_caption=element_markdown(color='blue', size=24)\n", " )" ] }, { "cell_type": "markdown", "id": "6665f53d-7863-453d-ab54-277caf233ff0", "metadata": {}, "source": [ "#### Style" ] }, { "cell_type": "code", "execution_count": 6, "id": "38d119e9-39e1-404d-9c76-1040dd8fb202", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p \\\n", " + ggtitle('*Hello*, **world**!') \\\n", " + theme(title=element_markdown())" ] }, { "cell_type": "markdown", "id": "56ad6bde-e55e-4e7c-9954-aadf9f352fb4", "metadata": {}, "source": [ "#### Span style color overrides theme color" ] }, { "cell_type": "code", "execution_count": 7, "id": "379bbe77-b0c7-4c7e-9f3b-0dd58277b589", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p \\\n", " + ggtitle('*Hello*, **orange** and ***red***!') \\\n", " + theme(title=element_markdown(color='blue'))" ] }, { "cell_type": "markdown", "id": "c153996b-ded8-48b3-9130-ba8e83d82c10", "metadata": {}, "source": [ "## TODO:" ] }, { "cell_type": "markdown", "id": "e9af3bad-242c-4fb7-a765-64a6f2d32908", "metadata": {}, "source": [ "#### LaTeX" ] }, { "cell_type": "code", "execution_count": 8, "id": "426445f5-3907-4229-8ced-6ff5df1191a2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot() \\\n", " + geom_blank() \\\n", " + ggtitle(\"***Markdown title*** **\\\\( a^2 + b^2 = c^2 \\\\)**\") \\\n", " + ggsize(400, 200)\n", "\n", "gggrid([\n", " p, \n", " p + theme(plot_title=element_markdown())]) \\\n", " + ggsize(800, 200)" ] }, { "cell_type": "markdown", "id": "4f70f396-43ee-4e8c-a52e-dcbef60d757d", "metadata": {}, "source": [ "#### br" ] }, { "cell_type": "code", "execution_count": 9, "id": "813c4856-dbca-455e-a228-59ded1b51a8f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot() \\\n", " + geom_blank() \\\n", " + labs(title='*Hello*,
**world**') \\\n", " + theme(title=element_markdown()) \\\n", " + ggsize(400, 200)\n", "p" ] }, { "cell_type": "markdown", "id": "8d564763-15fb-481d-a599-67f622e27405", "metadata": {}, "source": [ "#### Geoms" ] }, { "cell_type": "code", "execution_count": 10, "id": "bf0d579a-84f1-471f-98da-267382389273", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_label(x=0, y=0, label=\"*Hello*, **world**\") + ggsize(400, 200)" ] }, { "cell_type": "markdown", "id": "1940fe11-192d-4361-863a-382689b09a99", "metadata": {}, "source": [ "#### Hyperlink" ] }, { "cell_type": "code", "execution_count": 11, "id": "3f9580d7-7c53-47ef-b562-65ba42624e1f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() \\\n", " + geom_blank() \\\n", " + ggtitle('*Hello*, [**lets-plot**](https://lets-plot.org)!') \\\n", " + theme(title=element_markdown()) \\\n", " + ggsize(400, 200)" ] }, { "cell_type": "markdown", "id": "08b5b501-d0d7-4771-b361-a70ead21481b", "metadata": {}, "source": [ "#### Tooltips" ] }, { "cell_type": "code", "execution_count": 12, "id": "81c4971c-58dc-490f-82c1-c78c2b70bafa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() \\\n", " + geom_point(x=0, y=0, tooltips=layer_tooltips().line(\"*Hello*, [**lets-plot**](https://lets-plot.org)!\")) \\\n", " + ggsize(400, 200)" ] } ], "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.12.8" } }, "nbformat": 4, "nbformat_minor": 5 }