{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pandas import DataFrame\n", "import numpy as np\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load MPG dataset\n", "import pandas as pd\n", "\n", "mpg = pd.read_csv (\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ggplot(mpg, aes('displ', 'hwy', color='manufacturer')) \\\n", "+ geom_point(size=5, tooltips=layer_tooltips()\n", " .anchor('top_right')\n", " .min_width(180) \n", " .line('@manufacturer @model')\n", " .line('cty/hwy|@cty/@hwy')\n", " .line('@|@class')\n", " .line('@|@year'))\\\n", "+ theme(legend_position='bottom') \\\n", "+ ggsize(500,400)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Load the iris dataset\n", "iris_df = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(ggplot(iris_df) \n", " + geom_area(aes(x='sepal_length', fill='species'), \n", " stat='density',\n", " color='white',\n", " tooltips=layer_tooltips()\n", " .anchor('top_right')\n", " .line('^fill')\n", " .line('length|^x')\n", " .line('density|^y'))\n", " + ggsize(650, 300) \n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Two layers with their own tooltip anchor settings\n", "ggplot(iris_df) \\\n", "+ geom_line(aes(x='sepal_length', y='sepal_width'), colour='magenta',\n", " tooltips=layer_tooltips().line('width|^y').anchor('top_right')) \\\n", "+ geom_line(aes(x='petal_length', y='petal_width'), color='blue',\n", " tooltips=layer_tooltips().line('width|^y').anchor('top_left'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ggplot(iris_df) \\\n", "+ geom_line(aes(x='sepal_length', y='sepal_width'), colour='magenta',\n", " tooltips=layer_tooltips().line('sepal width|^y').anchor('top_right')) \\\n", "+ geom_line(aes(x='petal_length', y='petal_width'), color='blue',\n", " tooltips=layer_tooltips().line('petal width|^y').anchor('bottom_right'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ggplot(iris_df) \\\n", "+ geom_line(aes(x='sepal_length', y='sepal_width'), colour='magenta',\n", " tooltips=layer_tooltips().line('sepal width|^y').anchor('middle_left')) \\\n", "+ geom_line(aes(x='petal_length', y='petal_width'), color='blue',\n", " tooltips=layer_tooltips().line('petal width|^y').anchor('middle_left'))" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 4 }