WeCodeAcademy

Axis Limits, Ticks and Grids

By default matplotlib picks the axis range for you. Take control when it matters: ax.set_ylim(0, 100) fixes the vertical range, ax.set_xlim(a, b) the horizontal one. ax.set_xticks([...]) chooses where the tick marks sit, and ax.grid(True) adds faint guide lines that make values easier to read off.

A fixed range is also how you keep several charts comparable: give them all the same set_ylim and equal bars really do look equal.

Examplepython
Open in editor »
Quick check

What does `ax.set_ylim(0, 100)` do?

Your turn: write the code

Set the vertical range from 0 to 50 and print the limits (use print(ax.get_ylim())).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.