Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchSet a Matplotlib bar chart’s y-axis range with ax.set_ylim(bottom, top) after plotting. For example, ax.set_ylim(0, 100) displays a range from 0 to 100; choose bounds that fit your data.
Set both y-axis limits with Axes.set_ylim()
The object-oriented Matplotlib method sets the y-axis view limits in data coordinates:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
labels = ["A", "B", "C"]
values = [25, 60, 45]
fig, ax = plt.subplots()
ax.bar(labels, values)
ax.set_ylim(0, 80)
plt.show()
Here, the chart displays values from 0 through 80. The chosen bounds are examples, not recommended limits for every dataset. Matplotlib’s Axes.set_ylim API documents the method and its arguments.
Set only one bound, or use pyplot
Change just the upper or lower limit
Pass a named argument to change one bound while leaving the other unchanged. Passing None has the same effect for that bound.
#1 Best Overall
ax.set_ylim(top=80) # Keep the current lower limit
ax.set_ylim(bottom=0) # Keep the current upper limit
ax.set_ylim(bottom=None, top=80)
Use plt.ylim() in pyplot-style code
The pyplot function sets limits on the current Axes, so it fits a simple chart when you are not working with a retained Axes variable:
plt.bar(labels, values)
plt.ylim(0, 80)
For a figure with multiple subplots, prefer ax.set_ylim(...) to make clear which chart is being changed. The plt.ylim API describes the pyplot equivalent and its behavior when called without arguments.
Rank #2
Check the current limits and handle autoscaling
Read the current bounds with ax.get_ylim(). In pyplot style, call plt.ylim() without arguments to inspect the current Axes’ limits. Matplotlib normally derives view limits from the data and applies margins; its current stable autoscaling guide documents a default margin of 5%. The autoscaling guide explains how view limits and data limits interact.
Recommended Free Tools
Setting limits explicitly fixes the displayed range and turns y-axis autoscaling off by default. If you add more bars or other artists later, the view may not expand to include them. To fit the data again, use the Axes autoscaling controls, such as ax.autoscale() or ax.autoscale_view(), as appropriate to the Axes state. See also the APIs for ax.get_ylim() and ax.autoscale_view().
Reverse the y-axis intentionally
Limits do not have to be in ascending order. Setting the bottom value higher than the top reverses the axis, so values decrease from bottom to top:
ax.set_ylim(80, 0)
Use this only when an inverted y-axis is intended; the usual upward-increasing orientation uses ascending limits.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Version note
The linked API pages use Matplotlib’s /stable/ documentation, which can change as releases advance. If your project pins an older Matplotlib version, consult documentation matching that installation.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




