Reputation: 557
import numpy as np
import matplotlib.pyplot as plt
n = 1000
x = np.arange(0, n)
y1 = np.random.normal(50, 4, n)
y2 = np.random.normal(25, 2.5, n)
y3 = np.random.normal(10, 1.1, n)
fig, (ax1, ax2, ax3) = plt.subplots(nrows = 3, ncols = 1)
ax1.plot(x, y1, 'royalblue')
ax1.set(xticks = [], title = 'Title')
ax2.plot(x, y2, 'darkorange')
ax2.set(xticks = [])
ax3.plot(x, y3, 'forestgreen')
ax3.set(xlabel = 'Random sample')
fig.legend(['First', 'Second', 'Third'])
plt.show()
I would like the ylabels
to be shown in percentage, start at 0% and decrease. For example the blue one should go from [30, 40, 50, 60, 70]
to [-57.1%, -42.9%, -28.6%, -14.3%, 0%]
. The yellow one should go from [10, 20, 30, 40]
to [-75%, -50%, -25%, 0%]
and the green one should go from [5, 7.5, 10, 12.5, 15]
to [-66.6%, -50%, -33.3%, -16.7%, 0%]
.
The rest of the graphs should look exactly the same, only the ylabels
should change.
Upvotes: 0
Views: 45
Reputation: 6506
Just convert your current yticks to floats and change to the range you want them to be at before displaying:
import numpy as np
ticks = [float(x) for x in yvals]
ticks = np.array(ticks) - max(ticks)
yticklabels = ['{0:.1%}'.format(x) for x in ticks]
Do this for each plot separately.
Upvotes: 1