ylim
can be set using Axes.set()
. In fact a whole host of properties can be set via set()
, such as ticks, ticklabels, labels, title etc. (that were set separately in the OP).
ax = plt.gca()
ax.set(ylim=(20, 250), xlim=(0, 100))
Then again, ylim
(and other properties) can be set in the plt.subplot
instance as well. For the case in the OP, that would be
aPlot = plt.subplot(321, facecolor='w', title="Year 1", ylim=(20,250), xticks=paramValues, ylabel='Average Price', xlabel='Mark-up')
# ^^^^ <---- ylim here
plt.plot(paramValues, plotDataPrice[0], color='#340B8C', marker='o', ms=5, mfc='#EB1717');
To set ylim
(and other properties) for multiple subplots, use plt.setp
. For example, if we include 2 more subplots to OP's code and if we want to set the same properties to all of them, one way to do it would be as follows:
import matplotlib.pyplot as plt
import random
plt.figure(1, figsize = (8.5,11))
plt.suptitle('plot title')
ax = []
paramValues = range(10)
for i in range(1, 4):
aPlot = plt.subplot(3,2,i, title=f"Year {i}")
ax.append(aPlot)
aPlot.plot(paramValues, [random.randint(20,200) for _ in paramValues], color='#340B8C', marker='o', ms=5, mfc='#EB1717')
aPlot.grid(True);
plt.setp(ax, ylim=(20,250), facecolor='w', xticks=paramValues, ylabel='Average Price', xlabel='Mark-up')
# ^^^^ <---- ylim here
plt.tight_layout();