College Majors Axis Limits Not Automatic

Screen Link:
Basics.ipynb (145.6 KB)

My Code:

Paste your code here

What I expected to happen:
I expected for the y and x axis limits to automatically be set to fit the data

What actually happened:
The x and y limits were way off

Paste output/error here

Click here to view the jupyter notebook file in a new tab
1 Like

Hi @coffmanfb45,

This is the default behaviour of scatter plots in matplotlib:

x = [1, 2, 3]
y = [10, 20, 40]
plt.scatter(x, y)


To make the axes start with the minimum value and end in the maximum value. You can use plt.xlim() and plt.ylim() like this:

x = [1, 2, 3]
y = [10, 20, 40]
plt.xlim(min(x), max(x))
plt.ylim(min(y), max(y))
plt.scatter(x, y)


You will notice that the values are still there, but it’s barely visible. This is why the default behaviour of scatter plots is to set the axes larger than the value range.