#!/usr/bin/env python # coding: utf-8 # # `geom_curve()` # # # Specific arguments: # # * `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. # # * `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. # # * `ncp` The number of control points used to draw the curve. More control points produce a smoother curve. Default = 5. # In[1]: import pandas as pd from lets_plot import * # In[2]: LetsPlot.setup_html() # In[3]: def curve_plot(curvature=0.5, angle=90.0, ncp=5): return ggplot() \ + geom_curve(x=-10, y=1, xend=10, yend=-1, curvature=curvature, angle=angle, ncp=ncp, arrow=arrow(ends='both')) \ + ggtitle("curvature={0}, angle={1}, ncp={2}".format(curvature, angle, ncp)) \ + xlim(-15,15) # In[4]: gggrid([ curve_plot(angle=0), curve_plot(ncp=1), curve_plot(angle=45), curve_plot(curvature=-1, angle=45), curve_plot(curvature=0.7, angle=30), curve_plot(curvature=-0.7, angle=30), ], ncol=2) # #### Annotate Objects on Plot # In[5]: mpg = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv") mpg.head(3) # In[6]: mpg_cyl5 = mpg.loc[(mpg['cyl'] == 5) & (mpg['model'] == 'new beetle')] ggplot(mpg, aes('displ', 'hwy')) \ + geom_point(data=mpg_cyl5, color='#de77ae', size=5) \ + geom_point() \ + geom_text(label="Five-cylinder engine", x=4, y=40, nudge_x=0.5, color='#c51b7d', size=10) \ + geom_curve(data=mpg_cyl5, xend=4, yend=40, size_start=6, size_end=15, curvature=0.3, arrow=arrow(length=8, ends='first', angle=15, type="closed"), size=0.3, color='#c51b7d') # In[7]: (ggplot(mpg) + geom_bar(aes(x="class")) + geom_curve(x=5, y=55, xend=3, yend=6, size_start=50, arrow=arrow(length=10, ends='last', type="closed")) + geom_text(label="Zoom Zoom!", x=5, y=55) )