PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated 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 matchFor an existing Matplotlib axes, call ax.set_yscale('log') to make its y-axis logarithmic. The default base is 10; choose another with base=. A standard log scale cannot show zero or negative measurements as themselves. If your data crosses zero, use symlog with a linear region controlled by linthresh, or choose a different scale if that better represents the data.
Set the y-axis to a logarithmic scale
Use the object-oriented Axes method after creating the plot:
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_yscale('log')
plt.show()
set_yscale applies the scale to the y-axis, including its data-to-position transform and scale-appropriate tick locators and formatters. See Matplotlib’s Axes.set_yscale API and axis scales guide.
Free tools Windows power users keep installed
One-click scans. No signup required.
Choose a logarithm base
The ordinary log scale defaults to base 10. Pass another base when that suits the data or the way you want to interpret equal intervals on the axis:
#1 Best Overall
ax.set_yscale('log', base=2)
For example, a base-2 axis is useful when powers of two are meaningful to the reader. Changing the base changes the logarithmic scale and its tick spacing; it does not change the underlying measurements. Matplotlib’s log-scale example documents the default base and the base parameter.
What happens to zero and negative values?
A real logarithm is undefined at zero and for negative values, so an ordinary log axis cannot display those measurements at their actual values. Matplotlib provides two ways to handle non-positive values, selected with nonpositive:
Rank #2
ax.set_yscale('log', nonpositive='mask')masks non-positive values. Plot segments or artists that rely on those values may be omitted.ax.set_yscale('log', nonpositive='clip')clips them to a small positive value. This can keep some elements, such as an error bar extending below zero, visible near the lower plot edge, but it changes their visual representation.
Clipping does not make zero or a negative measurement mathematically valid on a log axis. Matplotlib’s log-scale example illustrates these behaviors with error bars; choose the handling that accurately communicates what the data show.
Recommended Free Tools
Use symlog when values cross zero
The symlog scale supports negative and positive values by using a linear region around zero and logarithmic scaling farther from it:
ax.set_yscale('symlog', linthresh=1)
linthresh is in the units of your data. Set it to the range around zero where you need linear resolution. Matplotlib suggests a threshold near the smallest absolute data value as a rule of thumb, often leaving no more than a few points in the linear region; the suitable choice depends on the data and chart. The transition between linear and logarithmic regions has a gradient discontinuity, so the apparent rate of change can shift at the boundary.
The optional linscale parameter changes how much visual space the linear region occupies. Adjust it deliberately: the displayed distances are part of how readers interpret the values. See Matplotlib’s symlog guide for the scale’s behavior and parameters.
Choose the scale that fits the measurements
| Scale | Values around zero | Controls and considerations |
|---|---|---|
log |
Non-positive values cannot be shown as themselves. | base sets the logarithm base; nonpositive='mask' or 'clip' controls treatment of non-positive values. Use when values are positive and logarithmic distances make sense. |
symlog |
Supports negative and positive values with a linear band around zero. | linthresh sets the linear region; linscale adjusts its visual width, and base sets the logarithmic base. The linear-to-log transition has a gradient discontinuity. |
asinh |
Matplotlib presents it as an alternative for wide-ranging values with a smooth gradient. | linear_width controls the scale. Consider it when a smooth transition is desirable, and make sure the transform communicates the data appropriately. |
These scales make different visual trade-offs; none is universally best. Matplotlib discusses them in its axis scales guide.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick Recap
Best Value
Check the result against your data
- Confirm whether zero and negative values are meaningful observations or invalid entries for the chart’s purpose.
- If using ordinary
log, inspect the plotted range and any masked or clipped artists so the treatment is not mistaken for the original measurement. - If using
symlog, chooselinthreshin the data’s units and check how the linear band and transition affect comparisons near zero. - Tick appearance and defaults can vary by Matplotlib release. These links point to the stable documentation available on October 7, 2026; your installed version may differ.
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.




