geom_curve()#
Specific arguments:
curvatureA 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.angleA 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.ncpThe number of control points used to draw the curve. More control points produce a smoother curve. Default = 5.
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
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)
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#
mpg = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg.head(3)
| Unnamed: 0 | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
| 1 | 2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
| 2 | 3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
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')
(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)
)