matplotlib show percentage y axis

Solutions on MaxInterview for matplotlib show percentage y axis by the best coders in the world

showing results for - "matplotlib show percentage y axis"
Antonio
22 May 2020
1import matplotlib.pyplot as plt
2import numpy as np
3import matplotlib.ticker as mtick
4
5data = [8,12,15,17,18,18.5]
6perc = np.linspace(0,100,len(data))
7
8fig = plt.figure(1, (7,4))
9ax = fig.add_subplot(1,1,1)
10
11ax.plot(perc, data)
12
13fmt = '%.0f%%' # Format you want the ticks, e.g. '40%'
14xticks = mtick.FormatStrFormatter(fmt)
15ax.xaxis.set_major_formatter(xticks)
16
17plt.show()