Matplotlib get ylim values

I use matplotlib to build data (using plot and errorbar ) from Python. I need to build a set of completely separate and independent charts, and then adjust their ylim values ylim that they can be visually compared.

How can I get the ylim values โ€‹โ€‹from each graph so that I can take the min and max of the lower and upper ylim values โ€‹โ€‹respectively and adjust the graphs so that they can be visually compared?

Of course, I could just ylim data and come up with my own ylim values โ€‹โ€‹... but I would like to use matplotlib for this. Any suggestions on how easy (and efficient) to do this?

Here is my Python function using matplotlib :

 import matplotlib.pyplot as plt def myplotfunction(title, values, errors, plot_file_name): # plot errorbars indices = range(0, len(values)) fig = plt.figure() plt.errorbar(tuple(indices), tuple(values), tuple(errors), marker='.') # axes axes = plt.gca() axes.set_xlim([-0.5, len(values) - 0.5]) axes.set_xlabel('My x-axis title') axes.set_ylabel('My y-axis title') # title plt.title(title) # save as file plt.savefig(plot_file_name) # close figure plt.close(fig) 
+43
python matplotlib plot
Sep 30 '14 at 23:05
source share
2 answers

Just use axes.get_ylim() , it is very similar to set_ylim . From docs :

get_ylim ()

Get y-axis range [bottom, top]

+57
Sep 30 '14 at 23:12
source share
  ymin, ymax = axes.get_ylim() 

If you use the plt structure, why bother with axes? This should work:

 def myplotfunction(title, values, errors, plot_file_name): # plot errorbars indices = range(0, len(values)) fig = plt.figure() plt.errorbar(tuple(indices), tuple(values), tuple(errors), marker='.') plt.xlim([-0.5, len(values) - 0.5]) plt.xlabel('My x-axis title') plt.ylabel('My y-axis title') # title plt.title(title) # save as file plt.savefig(plot_file_name) # close figure plt.close(fig) 

Or is it not so?

+17
Sep 30 '14 at 23:17
source share



All Articles