{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "victorian-aberdeen", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "import pandas as pd\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "id": "differential-tsunami", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_label(x=0, y=0, label='Lorem ipsum', size=14) + ggsize(500, 200)" ] }, { "cell_type": "code", "execution_count": 3, "id": "atmospheric-digit", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_label(x=0, y=0, \n", " label='Lorem ipsum', \n", " size=14, \n", " fill='#edf8e9', \n", " color='#238b45', \n", " fontface='bold',\n", " label_padding=1.0,\n", " label_r=0.5,\n", " label_size=2.0\n", " ) + ggsize(500, 200) " ] }, { "cell_type": "code", "execution_count": 4, "id": "plain-banana", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "families = [\n", " \"Arial\", \n", " \"Calibri\", \n", " \"Garamond\",\n", " \"Geneva\",\n", " \"Georgia\",\n", " \"Helvetica\",\n", " \"Lucida Grande\",\n", " \"Rockwell\",\n", " \"Times New Roman\",\n", " \"Verdana\",\n", " \"sans-serif\",\n", " \"serif\",\n", " \"monospace\"\n", "]\n", "ggplot() + geom_label(aes(y=list(range(len(families))), label=families, family=families), size=10,\n", " label_padding=0,\n", " label_r=0)" ] }, { "cell_type": "code", "execution_count": 5, "id": "simple-recipient", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = {\n", " 'hjust': [0, 0.5, 1],\n", " 'vjust': [0, 0.5, 1],\n", " 'angle': [0, 45, 90],\n", " 'text' : ['Text'] \n", "}\n", "\n", "from itertools import product\n", "td = pd.DataFrame(product(*d.values()), columns=d.keys())\n", "\n", "(ggplot(td, aes(x='hjust', y='vjust')) + \n", " geom_point(size=3) +\n", " geom_label(aes(label='text', angle='angle', hjust='hjust', vjust='vjust'), size=9) +\n", " facet_grid(y='angle') +\n", " scale_x_continuous(breaks=[0, 0.5, 1], expand=[0.1]) +\n", " scale_y_continuous(breaks=[0, 0.5, 1], expand=[0.0, 0.5]) +\n", " theme_classic() + theme(panel_border=element_rect(size=1))\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "cosmetic-employee", "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", "
miles per gallonnumber of cylindersengine displacement (cu. inches)engine horsepowervehicle weight (lbs.)time to accelerate (sec.)model yearorigin of carvehicle name
018.08307.0130350412.070USchevrolet chevelle malibu
115.08350.0165369311.570USbuick skylark 320
218.08318.0150343611.070USplymouth satellite
316.08304.0150343312.070USamc rebel sst
417.08302.0140344910.570USford torino
\n", "
" ], "text/plain": [ " miles per gallon number of cylinders engine displacement (cu. inches) \\\n", "0 18.0 8 307.0 \n", "1 15.0 8 350.0 \n", "2 18.0 8 318.0 \n", "3 16.0 8 304.0 \n", "4 17.0 8 302.0 \n", "\n", " engine horsepower vehicle weight (lbs.) time to accelerate (sec.) \\\n", "0 130 3504 12.0 \n", "1 165 3693 11.5 \n", "2 150 3436 11.0 \n", "3 150 3433 12.0 \n", "4 140 3449 10.5 \n", "\n", " model year origin of car vehicle name \n", "0 70 US chevrolet chevelle malibu \n", "1 70 US buick skylark 320 \n", "2 70 US plymouth satellite \n", "3 70 US amc rebel sst \n", "4 70 US ford torino " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv\")\n", "mpg.head()" ] }, { "cell_type": "code", "execution_count": 7, "id": "lined-series", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot(mpg.head(30), aes('vehicle weight (lbs.)', 'miles per gallon', label='vehicle name'))\n", "\n", "p + geom_label()" ] }, { "cell_type": "code", "execution_count": 8, "id": "communist-welding", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from lets_plot.mapping import as_discrete\n", "\n", "p + geom_label(aes(fill = as_discrete('number of cylinders', order=1)),\n", " color = 'white', \n", " fontface = 'bold'\n", " ) + ggsize(800,400)" ] }, { "cell_type": "code", "execution_count": 9, "id": "scientific-shirt", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from lets_plot.geo_data import *\n", "\n", "gcoder = geocode_states('us-48').inc_res()\n", "\n", "gplot = (ggplot() +\n", " geom_polygon(aes(fill='state'), \n", " data=gcoder.get_boundaries(), \n", " show_legend=False, \n", " color=\"white\",\n", " tooltips='none') +\n", " coord_map() +\n", " theme(axis='blank', panel_grid=\"blank\") +\n", " scale_fill_brewer(name=\"state\", palette=\"Dark2\") + \n", " ggsize(900, 500))\n", "\n", "gplot + geom_label(aes(label='state'), data=gcoder.get_centroids(), size=6)" ] }, { "cell_type": "code", "execution_count": 10, "id": "actual-cursor", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# livemap\n", "\n", "# Label parameters ('label_padding', 'label_r', 'label_size') are not yet supported on livemap.\n", "\n", "data = {\n", " 'city': ['New York City', 'Singapore'],\n", " 'lon': [-73.7997, 104.0012],\n", " 'lat': [40.6408, 1.3256],\n", "}\n", "\n", "(ggplot(data, aes(x='lon', y='lat')) +\n", " geom_livemap(geodesic=False, projection='epsg4326',\n", " symbol='point', color='white',\n", " tiles=maptiles_lets_plot(theme='dark')) +\n", " geom_path(color='white') +\n", " geom_label(aes(label='city'), fill='white', color='black', size=8, angle=10, hjust=0, vjust=1)\n", ")" ] } ], "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 }