{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "be99aa89", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "e73366e1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "cce7875d", "metadata": {}, "source": [ "### Setting Theme Parameters Via Sum In `set_theme()`" ] }, { "cell_type": "code", "execution_count": 3, "id": "b7246fcd", "metadata": {}, "outputs": [], "source": [ "LetsPlot.set_theme(theme_bw() \n", " + flavor_darcula() \n", " + theme(panel_background=element_rect(fill='yellow')))" ] }, { "cell_type": "code", "execution_count": 4, "id": "28e6fca6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {'name': ['pen', 'brush', 'paper'],\n", " 'slice': [1, 3, 3]}\n", "ggplot(data) + \\\n", " geom_pie(aes(fill='name', slice='slice'),\n", " stat='identity', color='pen',\n", " tooltips='none', labels=layer_labels().line('@name')) + \\\n", " scale_fill_manual(['pen', 'brush', 'paper'])" ] }, { "cell_type": "markdown", "id": "d61e5176", "metadata": {}, "source": [ "### The Last Theme Overwrites Previous Theme Settings" ] }, { "cell_type": "code", "execution_count": 5, "id": "8658ade3", "metadata": {}, "outputs": [], "source": [ "LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) \n", " + theme_bw() \n", " + flavor_darcula())" ] }, { "cell_type": "code", "execution_count": 6, "id": "d5f8d513", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {'name': ['pen', 'brush', 'paper'],\n", " 'slice': [1, 3, 3]}\n", "ggplot(data) + \\\n", " geom_pie(aes(fill='name', slice='slice'),\n", " stat='identity', color='pen',\n", " tooltips='none', labels=layer_labels().line('@name')) + \\\n", " scale_fill_manual(['pen', 'brush', 'paper'])" ] }, { "cell_type": "markdown", "id": "1087090e", "metadata": {}, "source": [ "The previous flavors are overwritten by the last flavor." ] }, { "cell_type": "code", "execution_count": 7, "id": "270b7b05", "metadata": {}, "outputs": [], "source": [ "LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) \n", " + theme_bw() \n", " + flavor_darcula() \n", " + flavor_high_contrast_light())" ] }, { "cell_type": "code", "execution_count": 8, "id": "b654b400", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {'name': ['pen', 'brush', 'paper'],\n", " 'slice': [1, 3, 3]}\n", "ggplot(data) + \\\n", " geom_pie(aes(fill='name', slice='slice'),\n", " stat='identity', color='pen',\n", " tooltips='none', labels=layer_labels().line('@name')) + \\\n", " scale_fill_manual(['pen', 'brush', 'paper'])" ] }, { "cell_type": "markdown", "id": "3d698321", "metadata": {}, "source": [ "### Overwriting of Local Theme" ] }, { "cell_type": "code", "execution_count": 9, "id": "bd206eac", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {'name': ['pen', 'brush', 'paper'],\n", " 'slice': [1, 3, 3]}\n", "ggplot(data) + \\\n", " geom_pie(aes(fill='name', slice='slice'),\n", " stat='identity', color='pen',\n", " tooltips='none', labels=layer_labels().line('@name')) + \\\n", " scale_fill_manual(['pen', 'brush', 'paper']) +\\\n", " theme(panel_background=element_rect(fill='yellow')) +\\\n", " theme_classic() +\\\n", " flavor_darcula() +\\\n", " flavor_high_contrast_light()" ] }, { "cell_type": "markdown", "id": "e34a54d0", "metadata": {}, "source": [ "### `gggrid()` and `GGbunch()`" ] }, { "cell_type": "code", "execution_count": 10, "id": "817006e4", "metadata": {}, "outputs": [], "source": [ "LetsPlot.set_theme(theme_bw() \n", " + flavor_darcula() \n", " + theme(panel_background=element_rect(fill='yellow')))" ] }, { "cell_type": "code", "execution_count": 11, "id": "3f3ac0c5", "metadata": {}, "outputs": [], "source": [ "np.random.seed(42)\n", "n = 100\n", "x = np.arange(n)\n", "y = np.random.normal(size=n)\n", "w, h = 200, 150" ] }, { "cell_type": "code", "execution_count": 12, "id": "e4d5026e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h)\n", "plot_list=[\n", " gggrid([p+geom_point(), p+geom_histogram(bins=3)]),\n", " p+geom_line()\n", "]\n", "gggrid(plot_list, ncol=1) + ggsize(400, 300)" ] }, { "cell_type": "code", "execution_count": 13, "id": "df3020bc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h)\n", "bunch = GGBunch()\n", "bunch.add_plot(p + geom_point(), 0, 0)\n", "bunch.add_plot(p + geom_histogram(bins=3), w, 0)\n", "bunch.add_plot(p + geom_line(), 0, h, 2*w, h)\n", "bunch.show()" ] }, { "cell_type": "markdown", "id": "5b9ebff5", "metadata": {}, "source": [ "### Wrong Type Exception" ] }, { "cell_type": "code", "execution_count": 14, "id": "f07696fa", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[14], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mLetsPlot\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_theme\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtheme\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpanel_background\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43melement_rect\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfill\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43myellow\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mtheme_bw\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\n\u001b[0;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mflavor_darcula\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\n\u001b[0;32m 4\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mflavor_high_contrast_light\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mgeom_point\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python310\\site-packages\\lets_plot\\__init__.py:175\u001b[0m, in \u001b[0;36mLetsPlot.set_theme\u001b[1;34m(cls, theme)\u001b[0m\n\u001b[0;32m 165\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 166\u001b[0m \u001b[38;5;124;03mSet up global theme.\u001b[39;00m\n\u001b[0;32m 167\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 172\u001b[0m \n\u001b[0;32m 173\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 174\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m theme\u001b[38;5;241m.\u001b[39mkind \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtheme\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (theme\u001b[38;5;241m.\u001b[39mkind \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfeature-list\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mall\u001b[39m(f\u001b[38;5;241m.\u001b[39mkind \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtheme\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m f \u001b[38;5;129;01min\u001b[39;00m theme)):\n\u001b[1;32m--> 175\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOnly `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 177\u001b[0m _set_global_theme(theme)\n", "\u001b[1;31mValueError\u001b[0m: Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported" ] } ], "source": [ "LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) \n", " + theme_bw() \n", " + flavor_darcula() \n", " + flavor_high_contrast_light()\n", " + geom_point())" ] } ], "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.10.11" } }, "nbformat": 4, "nbformat_minor": 5 }