Using a non-linear axis scale

Depending on the distribution of our data, a linear scale may not be the best way to fit in all useful data points in a figure. In this case, we may need to modify the scale of the axes into a log or symmetric log scale. In Matplotlib, this can be done by plt.xscale() and plt.yscale() before defining the axes, or by ax.set_xscale() and ax.set_yscale() after an axis is defined.

We do not need to change the scale of the entire axis. To display a part of the axis in linear scale, we adjust the linear threshold with the argument linthreshx or linthreshy. To obtain a smooth continuous line, we can also mask the non-positive numbers with the argument nonposx or nonposy.

The following code snippet is an example of the ...

Get Matplotlib for Python Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.