Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I need help with setting the limits of y-axis on matplotlib. Here is the code that I tried, unsuccessfully.

import matplotlib.pyplot as plt

plt.figure(1, figsize = (8.5,11))

plt.suptitle('plot title')

ax = []

aPlot = plt.subplot(321, axisbg = 'w', title = "Year 1") ax.append(aPlot)

plt.plot(paramValues,plotDataPrice[0], color = '#340B8C',

marker = 'o', ms = 5, mfc = '#EB1717') plt.xticks(paramValues)

plt.ylabel('Average Price')

plt.xlabel('Mark-up')

plt.grid(True)

plt.ylim((25,250))

With the data I have for this plot, I get y-axis limits of 20 and 200. However, I want the limits 20 and 250.

1 Answer

0 votes
by (106k points)

For setting the limits of the y-axis on matplotlib you can use the following code which will work for subplots as well:-

axes = plt.gca()

axes.set_xlim([xmin,xmax])

axes.set_ylim([ymin,ymax])

Another way you can do this problem by changing only the y-values:

x1,x2,y1,y2 = plt.axis()

plt.axis((x1,x2,25,250))

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 9, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers

501 comments

104k users

Browse Categories

...