from plotnine import ggplot, aes, labs, geom_point, theme, theme_538, theme_set
from plotnine.data import mtcars
theme_set(theme_538())
Text Outside Panel
text
= """\
caption This graphic illustrates the inverse relationship between vehicle weight
and fuel efficiency (MPG). It aims to highlight how heavier vehicles generally
consume more fuel, and how the complexity of an engine's cylinder count and
transmission system can affect its fuel economy.
"""
from plotnine import *
("mpg", "wt", colour="factor(cyl)", size="gear"))
ggplot(mtcars, aes(+ geom_point()
+ labs(
="Miles per Gallon",
x="Weight",
y="Cylinders",
colour="Gears",
size="Fuel Efficiency vs. Vehicle Weight",
title="Exploring Factors that Affect the Fuel Effeciency of a Car",
subtitle =caption,
caption
)
+ theme(
# left justify the caption and have one line of space between it and
# the x-axis label
=element_text(ha="left", margin={"t": 1, "units": "lines"})
plot_caption
)
)