expand_limits()¶When creating visualizations, you might occasionally need to adjust your plot boundaries to encompass specific data points or values. This is where the expand_limits() function comes in handy. It allows you to extend the plot's scales to include particular values, ensuring they're visible in your visualization.
from lets_plot import *
import pandas as pd
LetsPlot.setup_html()
mpg = pd.read_csv('https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv')
mpg.head(3)
p = ggplot(mpg, aes("miles per gallon", "vehicle weight (lbs.)")) + geom_point()
p
p + expand_limits(x=0)
p + expand_limits(y=[1000, 9000])
p + expand_limits(x = 0, y = 0)
# Add color mapping
p1 = p + aes(color="number of cylinders")
gggrid([
p1,
# Expand the color-scale limits.
p1 + expand_limits(color=range(2, 11, 2))
])