{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "unique-colonial", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "silent-production", "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", " \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", " \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
45audia42.819996auto(l5)f1626pcompact
.......................................
229230volkswagenpassat2.020084auto(s6)f1928pmidsize
230231volkswagenpassat2.020084manual(m6)f2129pmidsize
231232volkswagenpassat2.819996auto(l5)f1626pmidsize
232233volkswagenpassat2.819996manual(m5)f1826pmidsize
233234volkswagenpassat3.620086auto(s6)f1726pmidsize
\n", "

234 rows × 12 columns

\n", "
" ], "text/plain": [ " Unnamed: 0 manufacturer model displ year cyl trans drv cty \\\n", "0 1 audi a4 1.8 1999 4 auto(l5) f 18 \n", "1 2 audi a4 1.8 1999 4 manual(m5) f 21 \n", "2 3 audi a4 2.0 2008 4 manual(m6) f 20 \n", "3 4 audi a4 2.0 2008 4 auto(av) f 21 \n", "4 5 audi a4 2.8 1999 6 auto(l5) f 16 \n", ".. ... ... ... ... ... ... ... .. ... \n", "229 230 volkswagen passat 2.0 2008 4 auto(s6) f 19 \n", "230 231 volkswagen passat 2.0 2008 4 manual(m6) f 21 \n", "231 232 volkswagen passat 2.8 1999 6 auto(l5) f 16 \n", "232 233 volkswagen passat 2.8 1999 6 manual(m5) f 18 \n", "233 234 volkswagen passat 3.6 2008 6 auto(s6) f 17 \n", "\n", " hwy fl class \n", "0 29 p compact \n", "1 29 p compact \n", "2 31 p compact \n", "3 30 p compact \n", "4 26 p compact \n", ".. ... .. ... \n", "229 28 p midsize \n", "230 29 p midsize \n", "231 26 p midsize \n", "232 26 p midsize \n", "233 26 p midsize \n", "\n", "[234 rows x 12 columns]" ] }, "execution_count": 2, "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" ] }, { "cell_type": "code", "execution_count": 3, "id": "varied-seventh", "metadata": {}, "outputs": [], "source": [ "p = ggplot(mpg_df, aes(\"cty\",\"hwy\", color='drv')) + \\\n", " geom_point(tooltips=layer_tooltips().line('@manufacturer @model'))" ] }, { "cell_type": "code", "execution_count": 4, "id": "fewer-montreal", "metadata": {}, "outputs": [], "source": [ "p2 = p + facet_grid(y=\"drv\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "theoretical-missile", "metadata": {}, "outputs": [], "source": [ "w, h = 600, 400\n", "\n", "def themeWithFlavor(plot, theme, title):\n", " bunch = GGBunch()\n", " bunch.add_plot(plot + theme + ggtitle(title), 0, 0, w, h) \n", " bunch.add_plot(plot + theme + flavor_darcula()+ ggtitle(\"darcula\"), w, 0, w, h) \n", " bunch.add_plot(plot + theme + flavor_solarized_light()+ ggtitle(\"solarized_light\"), 0, h, w, h) \n", " bunch.add_plot(plot + theme + flavor_solarized_dark()+ ggtitle(\"solarized_dark\"), w, h, w, h) \n", " bunch.add_plot(plot + theme + flavor_high_contrast_light()+ ggtitle(\"high_contrast_light\"), 0, h*2, w, h) \n", " bunch.add_plot(plot + theme + flavor_high_contrast_dark()+ ggtitle(\"high_contrast_dark\"), w, h*2, w, h) \n", " bunch.show()" ] }, { "cell_type": "code", "execution_count": 6, "id": "former-darkness", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_minimal2(), \"minimal2\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "decreased-utilization", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_minimal2(), \"minimal2 + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 8, "id": "developing-major", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_minimal(), \"minimal\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "widespread-robin", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_minimal(), \"minimal + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "configured-viking", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_classic(), \"classic\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "indian-custom", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_classic(), \"classic + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "revolutionary-aquatic", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_light(), \"light\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "soviet-creation", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_light(), \"light + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 14, "id": "blocked-packaging", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_grey(), \"grey\")" ] }, { "cell_type": "code", "execution_count": 15, "id": "stretch-uzbekistan", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_grey(), \"grey + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 16, "id": "exempt-mercy", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_none(), \"none\")" ] }, { "cell_type": "code", "execution_count": 17, "id": "affiliated-gathering", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_none(), \"none + facet_grid\")" ] }, { "cell_type": "code", "execution_count": 18, "id": "three-facing", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p, theme_bw(), \"bw\")" ] }, { "cell_type": "code", "execution_count": 19, "id": "helpful-tower", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "themeWithFlavor(p2, theme_bw(), \"bw + facet_grid\")" ] } ], "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.7.13" } }, "nbformat": 4, "nbformat_minor": 5 }