{ "cells": [ { "cell_type": "markdown", "id": "employed-rebate", "metadata": {}, "source": [ "# Text Setting for Annotations\n", "\n", "Use the `label_text` parameter in `theme()` to set basic text settings for annotations, using the `element_text()` function with the following parameters: \n", "\n", "- family - font family;\n", "- face - font face (\"plain\", \"italic\", \"bold\", \"bold_italic\");\n", "- size - text size, can also be specified via `layer_labels().size()`;\n", "- color - text color.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "arranged-meter", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "remarkable-toolbox", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "faced-integral", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0manufacturermodeldisplyearcyltransdrvctyhwyflclass
01audia41.819994auto(l5)f1829pcompact
12audia41.819994manual(m5)f2129pcompact
23audia42.020084manual(m6)f2031pcompact
34audia42.020084auto(av)f2130pcompact
\n", "
" ], "text/plain": [ " Unnamed: 0 manufacturer model displ year cyl trans drv cty hwy \\\n", "0 1 audi a4 1.8 1999 4 auto(l5) f 18 29 \n", "1 2 audi a4 1.8 1999 4 manual(m5) f 21 29 \n", "2 3 audi a4 2.0 2008 4 manual(m6) f 20 31 \n", "3 4 audi a4 2.0 2008 4 auto(av) f 21 30 \n", "\n", " fl class \n", "0 p compact \n", "1 p compact \n", "2 p compact \n", "3 p compact " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg_df = pd.read_csv (\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "mpg_df.head(4)" ] }, { "cell_type": "code", "execution_count": 4, "id": "academic-wholesale", "metadata": {}, "outputs": [], "source": [ "label_text_opts = element_text(family='Rockwell', face='bold', size=16, color='#542788')" ] }, { "cell_type": "markdown", "id": "suited-visit", "metadata": {}, "source": [ "#### Configure Text Labels for Bar Plot" ] }, { "cell_type": "code", "execution_count": 5, "id": "employed-flavor", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(mpg_df) + \\\n", " geom_bar(aes('class', fill='class'), labels=layer_labels().line('@..sumpct..')) + \\\n", " theme(label_text=label_text_opts)" ] }, { "cell_type": "markdown", "id": "reduced-discharge", "metadata": {}, "source": [ "#### Configure Text Labels for Pie Chart" ] }, { "cell_type": "code", "execution_count": 6, "id": "8083daa6-66c4-47d1-84ee-014ed78df766", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(mpg_df) + \\\n", " geom_pie(aes(fill='class'), size=26, hole=0.3, labels=layer_labels().line('@..proppct..')) + \\\n", " theme_void() + \\\n", " theme(label_text=label_text_opts)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.10" } }, "nbformat": 4, "nbformat_minor": 5 }