Convert Y-axis Labels to a Percentage in Python Matplotlib

The matplotlib.ticker library provides an easy way to convert the y-axis number formatting in Matplotlib. Here’s how to turn a decimal y-axis and display them as a percentage.

If your y-values are stored as a decimal, your axis should look something like this:

After you have created the axis variable, you can run this code to change to a percentage

import matplotlib.ticker as mtick

ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1, decimals=None, symbol='%', is_latex=False))

Posted

in

by

Tags: