{ "cells": [ { "cell_type": "markdown", "id": "incomplete-caribbean", "metadata": {}, "source": [ "# `geom_curve()`\n", "\n", "\n", "Specific arguments:\n", "\n", "* `curvature` A numeric value that indicates the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves and zero produces a straight line. Default = 0.5.\n", "\n", "* `angle` A numeric value between 0 and 180 that indicates the amount by which the control points of the curve should be skewed. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point. Default = 90.\n", "\n", "* `ncp` The number of control points used to draw the curve. More control points produce a smoother curve. Default = 5." ] }, { "cell_type": "code", "execution_count": 1, "id": "bibliographic-beijing", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "controversial-square", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "silent-senator", "metadata": {}, "outputs": [], "source": [ "def curve_plot(curvature=0.5, angle=90.0, ncp=5):\n", " return ggplot() \\\n", " + geom_curve(x=-10, y=1, xend=10, yend=-1, \n", " curvature=curvature, angle=angle, ncp=ncp,\n", " arrow=arrow(ends='both')) \\\n", " + ggtitle(\"curvature={0}, angle={1}, ncp={2}\".format(curvature, angle, ncp)) \\\n", " + xlim(-15,15)" ] }, { "cell_type": "code", "execution_count": 4, "id": "continued-triple", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " curve_plot(angle=0),\n", " curve_plot(ncp=1),\n", " curve_plot(angle=45),\n", " curve_plot(curvature=-1, angle=45),\n", " curve_plot(curvature=0.7, angle=30),\n", " curve_plot(curvature=-0.7, angle=30),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "amber-magnitude", "metadata": {}, "source": [ "#### Annotate Objects on Plot" ] }, { "cell_type": "code", "execution_count": 5, "id": "exterior-invention", "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", "
Unnamed: 0manufacturermodeldisplyearcyltransdrvctyhwyflclass
01audia41.819994auto(l5)f1829pcompact
12audia41.819994manual(m5)f2129pcompact
23audia42.020084manual(m6)f2031pcompact
\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", "\n", " fl class \n", "0 p compact \n", "1 p compact \n", "2 p compact " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg = pd.read_csv (\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 6, "id": "suspended-cheese", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg_cyl5 = mpg.loc[(mpg['cyl'] == 5) & (mpg['model'] == 'new beetle')]\n", "\n", "ggplot(mpg, aes('displ', 'hwy')) \\\n", " + geom_point(data=mpg_cyl5, color='#de77ae', size=5) \\\n", " + geom_point() \\\n", " + geom_text(label=\"Five-cylinder engine\", x=4, y=40, nudge_x=0.5, color='#c51b7d', size=10) \\\n", " + geom_curve(data=mpg_cyl5, xend=4, yend=40,\n", " size_start=6,\n", " size_end=15,\n", " curvature=0.3, arrow=arrow(length=8, ends='first', angle=15, type=\"closed\"),\n", " size=0.3,\n", " color='#c51b7d')" ] }, { "cell_type": "code", "execution_count": 7, "id": "c61918bf-b1d1-4988-a338-1f2facb757e6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(ggplot(mpg) + geom_bar(aes(x=\"class\"))\n", " + geom_curve(x=5, y=55, xend=3, yend=6,\n", " size_start=50,\n", " arrow=arrow(length=10, ends='last', type=\"closed\"))\n", " + geom_text(label=\"Zoom Zoom!\", x=5, y=55)\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.8.18" } }, "nbformat": 4, "nbformat_minor": 5 }