class plotnine.geoms.geom_line(mapping=None, data=None, **kwargs)[source]

Connected points


geom_line(mapping=None, data=None, stat='identity', position='identity',
          na_rm=False, inherit_aes=True, show_legend=None, arrow=None,
          lineend='butt', linejoin='round', **kwargs)

Only the mapping and data can be positional, the rest must be keyword arguments. **kwargs can be aesthetics (or parameters) used by the stat.

mappingaes, optional

Aesthetic mappings created with aes(). If specified and inherit.aes=True, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.


Default value












The bold aesthetics are required.

datadataframe, optional

The data to be displayed in this layer. If None, the data from from the ggplot() call is used. If specified, it overrides the data from the ggplot() call.

statstr or stat, optional (default: stat_identity)

The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.

positionstr or position, optional (default: position_identity)

Position adjustment. If it is a string, it must be registered and known to Plotnine.

na_rmbool, optional (default: False)

If False, removes missing values with a warning. If True silently removes missing values.

inherit_aesbool, optional (default: True)

If False, overrides the default aesthetics.

show_legendbool or dict, optional (default: None)

Whether this layer should be included in the legends. None the default, includes any aesthetics that are mapped. If a bool, False never includes and True always includes. A dict can be used to exclude specific aesthetis of the layer from showing in the legend. e.g show_legend={'color': False}, any other aesthetic are included by default.

See also


For documentation of other parameters.


import pandas as pd
import numpy as np

from plotnine import *
from import *

%matplotlib inline

Line plots

geom_line() connects the dots, and is useful for time series data.

date pce pop psavert uempmed unemploy
0 1967-07-01 507.4 198712 12.5 4.5 2944
1 1967-08-01 510.5 198911 12.5 4.7 2945
2 1967-09-01 516.3 199113 11.7 4.6 2958
3 1967-10-01 512.9 199311 12.5 4.9 3143
4 1967-11-01 518.1 199498 12.5 4.7 3066
    ggplot(economics, aes(x='date', y='uempmed'))
    + geom_line() # line plot
    + labs(x='date', y='median duration of unemployment')
<ggplot: (-9223372029847151335)>

You can put arrows at the end of a line:

    ggplot(economics, aes(x='date', y='pop'))
    + geom_line(arrow=arrow()) # add an arrow to the end of the line
    + labs(x='date', y='total population (,000)')
<ggplot: (-9223372029844498516)>

The arrow can be modified for a different look:

    ggplot(economics, aes(x='date', y='pop'))
    + geom_line(arrow=arrow(angle=35,      # defines the shape of the arrow head
                              ends="both",   # input what end to put the arrow on
                              type="closed", # defines arrow head type
    + labs(x='date', y='total population (,000)')
<ggplot: (7007807983)>

You can change the look of the line:

    ggplot(economics, aes(x='date', y='uempmed'))
    + geom_line(color='pink',        # set line colour
                  size=7,            # set line thickness
                  linetype='dashed'  # set line type
    + labs(x='date', y='median duration of unemployment')

<ggplot: (-9223372029846967836)>