Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting y-axis limit in matplotlib

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.

like image 985
Curious2learn Avatar asked Sep 23 '10 11:09

Curious2learn


2 Answers

Get current axis via plt.gca(), and then set its limits:

ax = plt.gca() ax.set_xlim([xmin, xmax]) ax.set_ylim([ymin, ymax]) 
like image 149
Hima Avatar answered Sep 20 '22 18:09

Hima


Another workaround is to get the plot's axes and reassign changing only the y-values:

x1,x2,y1,y2 = plt.axis()   plt.axis((x1,x2,25,250)) 
like image 28
thetarro Avatar answered Sep 17 '22 18:09

thetarro