lets_plot.geom_curve#

lets_plot.geom_curve(mapping=None, *, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, arrow=None, curvature=None, angle=None, ncp=None, spacer=None, color_by=None, **other_args)#

Draw a curved line.

Parameters:
mappingFeatureSpec

Set of aesthetic mappings created by aes() function. Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.

datadict or Pandas or Polars DataFrame

The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.

statstr, default=’identity’

The statistical transformation to use on the data for this layer, as a string. Supported transformations: ‘identity’ (leaves the data unchanged), ‘count’ (counts number of points with same x-axis coordinate), ‘bin’ (counts number of points with x-axis coordinate in the same bin), ‘smooth’ (performs smoothing - linear default), ‘density’ (computes and draws kernel density estimate).

positionstr or FeatureSpec, default=’identity’

Position adjustment. Either a position adjustment name: ‘dodge’, ‘dodgev’, ‘jitter’, ‘nudge’, ‘jitterdodge’, ‘fill’, ‘stack’ or ‘identity’, or the result of calling a position adjustment function (e.g., position_dodge() etc.).

show_legendbool, default=True

False - do not show legend for this layer.

samplingFeatureSpec

Result of the call to the sampling_xxx() function. To prevent any sampling for this layer pass value “none” (string “none”).

tooltipslayer_tooltips

Result of the call to the layer_tooltips() function. Specify appearance, style and content.

arrowFeatureSpec

Specification for arrow head, as created by arrow() function.

curvaturefloat, default=0.5

The amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves, and zero produces a straight line.

anglefloat, default=90

Angle in degrees, giving an amount to skew the control points of the curve. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point.

ncpint, default=5

The number of control points used to draw the curve. More control points creates a smoother curve.

spacerfloat, default=0.0

Space to shorten a curve by moving the start/end.

color_by{‘fill’, ‘color’, ‘paint_a’, ‘paint_b’, ‘paint_c’}, default=’color’

Define the color aesthetic for the geometry.

other_args

Other arguments passed on to the layer. These are often aesthetics settings used to set an aesthetic to a fixed value, like color=’red’, fill=’blue’, size=3 or shape=21. They may also be parameters to the paired geom/stat.

Returns:
LayerSpec

Geom object specification.

Notes

geom_curve() draws a curved lines.

geom_curve() understands the following aesthetics mappings:

  • x : x-axis value.

  • y : y-axis value.

  • xend : x-axis value.

  • yend : y-axis value.

  • alpha : transparency level of a layer. Accept values between 0 and 1.

  • color (colour) : color of the geometry lines. String in the following formats: RGB/RGBA (e.g. “rgb(0, 0, 255)”); HEX (e.g. “#0000FF”); color name (e.g. “red”); role name (“pen”, “paper” or “brush”).

  • size : line width.

  • linetype : type of the line. Codes and names: 0 = ‘blank’, 1 = ‘solid’, 2 = ‘dashed’, 3 = ‘dotted’, 4 = ‘dotdash’, 5 = ‘longdash’, 6 = ‘twodash’.

  • size_start : offset from the start coordinate (usually equal to the size of the point object from which the curve starts to avoid overlapping with it).

  • size_end : offset from the end coordinate (usually equal to the size of the point object from which the curve ends to avoid overlapping with it).

  • stroke_start : offset from the start coordinate (usually equal to the stroke of the point object from which the curve starts to avoid overlapping with it).

  • stroke_end : offset from the end coordinate (usually equal to the stroke of the point object from which the curve ends to avoid overlapping with it).

Examples

1from lets_plot import *
2LetsPlot.setup_html()
3ggplot() + geom_curve(x=0, y=0, xend=1, yend=0, curvature=0.7, angle=30)

1from lets_plot import *
2LetsPlot.setup_html()
3data = {'x': [-1, -1, 1, 1], 'y': [-1, 1, 1, -1]}
4ggplot(data, aes(x='x', y='y')) + \
5    geom_point(size=14) + \
6    geom_curve(xend=0, yend=0, size_start=14, \
7               curvature = -0.5, \
8               arrow = arrow(ends='first')) + \
9    coord_fixed()

 1from lets_plot import *
 2LetsPlot.setup_html()
 3city = ["Moscow", "Oryol", "Novocherkassk", "Stavropol", \
 4       "Georgiyevsk", "Vladikavkaz", "Tiflis", "Kars", "Erzurum"]
 5latitude = [55.751244, 52.929697, 47.414101, 45.0428, \
 6           44.1497667, 43.03667, 41.716667, 40.60199, 39.90861]
 7longitude = [37.618423, 36.098689, 40.110401, 41.9734, \
 8            43.4577689, 44.66778, 44.783333, 43.09495, 41.27694]
 9pushkin_1829_cities = {"city": city, "latitude": latitude, "longitude": longitude}
10pushkin_1829_path = {
11    "from_lon": longitude[:-1],
12    "from_lat": latitude[:-1],
13    "to_lon": longitude[1:],
14    "to_lat": latitude[1:]
15}
16ggplot() + \
17    geom_livemap(const_size_zoomin=0) + \
18    geom_curve(aes("from_lon", "from_lat", xend="to_lon", yend="to_lat"), data=pushkin_1829_path, \
19               size_end=3, color="#fc4e2a", curvature=-0.2, arrow=arrow(type='closed', length=5)) + \
20    geom_point(aes("longitude", "latitude"), data=pushkin_1829_cities, \
21               size=3, color="#fc4e2a", tooltips=layer_tooltips().line("@city"))