Connected points
Usage
geom_line(mapping=None, data=None, stat='identity', position='identity',
na_rm=False, inherit_aes=True, show_legend=None, raster=False,
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
.
aes
, optionalAesthetic 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.
Aesthetic |
Default value |
---|---|
x |
|
y |
|
alpha |
|
color |
|
group |
|
linetype |
|
size |
|
The bold aesthetics are required.
dataframe
, optionalThe 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.
str
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.
str
or position, optional (default: position_identity
)Position adjustment. If it is a string, it must be registered and known to Plotnine.
False
)If False
, removes missing values with a warning. If True
silently removes missing values.
True
)If False
, overrides the default aesthetics.
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.
False
)If True
, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
See also
plotnine.geoms.geom_path
For documentation of other parameters.
[1]:
import pandas as pd
import numpy as np
from plotnine import *
from plotnine.data import *
%matplotlib inline
geom_line()
connects the dots, and is useful for time series data.
[2]:
economics.head()
[2]:
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 |
[3]:
(
ggplot(economics, aes(x='date', y='uempmed'))
+ geom_line() # line plot
+ labs(x='date', y='median duration of unemployment')
)
[3]:
<ggplot: (97654321012345679)>
You can put arrows at the end of a line:
[4]:
(
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)')
)
[4]:
<ggplot: (97654321012345679)>
The arrow can be modified for a different look:
[5]:
(
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)')
)
[5]:
<ggplot: (97654321012345679)>
You can change the look of the line:
[6]:
(
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')
)
[6]:
<ggplot: (97654321012345679)>