import pandas as pd
from plotnine import (
ggplot,
aes,
geom_point,
geom_line,
geom_linerange,
element_blank,
element_rect,
theme,
theme_matplotlib,
theme_set,
)
# Set default theme
# matplotlib + the background of 538
theme_set(
theme_matplotlib()
+ theme(
plot_background=element_rect(fill="#F0F0F0"),
panel_background=element_rect(fill="#F0F0F0"),
)
) plotnine.geom_linerange
Vertical interval represented by lines
{usage}
Examples
Upper & Lower Trends
The data
Create the line ranges
Add points at each end of the ranges.

Add a trend-line along the top of the ranges and one along the bottom of the ranges. The line is added before(below) the points.

Add some color.
# Gallery, lines
magenta = "#9E2F68"
magenta_light = "#E5C8D6"
sea_green = "#2F9E65"
sea_green_light = "#C8E5D7"
(ggplot(df, aes("x", "y"))
+ geom_linerange(aes(ymin="y-2", ymax="y"))
+ geom_line(color=magenta, size=3)
+ geom_point(color=magenta, fill=magenta_light, size=3, stroke=0.5)
+ geom_line(aes(y="y-2"), color=sea_green, size=3)
+ geom_point(aes(y="y-2"), color=sea_green, fill=sea_green_light, size=3, stroke=0.5)
)
