Control Axis Limits of Plot

logo of a chart:ScatterPlot

This post provides a reproducible code to plot a basic scatterplot with seaborn. The example shows how to control x and y axis limits of the plot using matplotlib functions plt.xlim() and plt.ylim().

Basic Scatterplot with Defined Axis Limits

You can control the limits of X and Y axis of your plots using matplotlib function plt.xlim() and plt.ylim(). In this example, lmplot() function of seaborn is used to plot a basic scatterplot with iris dataset. There are 2 arguments in these functions;

  • plt.xlim() : (left, right)
  • plt.ylim() : (buttom, top)
# library & dataset
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
 
# basic scatterplot
sns.scatterplot(
   x="sepal_length",
   y="sepal_width",
   data=df
)
 
# control x and y limits
plt.ylim(0, 20)
plt.xlim(0, None)
 
plt.show()

Going further

This post explains how to customize the appearance of the markers in a scatter plot with seaborn.

You might be interested in

Contact & Edit


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!