This is a few months late, but I have created PR#6251 with matplotlib to add a new PercentFormatter
class. With this class you can do as follows to set the axis:
import matplotlib.ticker as mtick
# Actual plotting code omitted
ax.xaxis.set_major_formatter(mtick.PercentFormatter(5.0))
This will display values from 0 to 5 on a scale of 0% to 100%. The formatter is similar in concept to what @Ffisegydd suggests doing except that it can take any arbitrary existing ticks into account.
PercentFormatter()
accepts three arguments, max
, decimals
, and symbol
. max
allows you to set the value that corresponds to 100% on the axis (in your example, 5
).
The other two parameters allow you to set the number of digits after the decimal point and the symbol. They default to None
and '%'
, respectively. decimals=None
will automatically set the number of decimal points based on how much of the axes you are showing.
Note that this formatter will use whatever ticks would normally be generated if you just plotted your data. It does not modify anything besides the strings that are output to the tick marks.
Update
PercentFormatter
was accepted into Matplotlib in version 2.1.0.