title: save a plot resulting from a function matplotlib python
body: <p>I created a function that takes a range of values from a data set and outputs a plot. For instance:</p>
  
  <p><code>my_plot(location_dataset, min_temperature, max_temperature)</code> will return a plot of precipitation for the range of temperature specified in the function.</p>
  
  <p>Let's say I want to save the plot for the temperature between 60-70F in California. so, I would call my function <code>my_plot(California, 60, 70)</code> and will get a plot of precipitation for California when temperatures are between 60 and 70F.</p>
  
  <p>My question is: how do I save a plot that results from calling a function into a jpeg format?</p>
  
  <p>I know of <code>plt.savefig()</code> when it is not the result of calling a function but in my case how do I do this? </p>
  
  <p>Thanks!</p>
  
  <p>More details: here is my code (heavily simplified):</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  def my_plot(location_dataset, min_temperature, max_temperature):
      condition = (location_dataset['temperature'] &gt; min_temperature) &amp; (dataset['temperature'] &lt;= max_temperature)
      subset = location_dataset[condition] # subset the data based on the temperature range
  
      x = subset['precipitation'] # takes the precipitation column only
      plt.figure(figsize=(8, 6))
      plt.plot(x)
      plt.show()
  </code></pre>
  
  <p>So then I call this function as follow: <code>my_plot(California, 60, 70)</code> and I get my plot for the 60-70 temperature range. how do I save this plot without having the <code>savefig</code> inside the function definition (and that is because I need to change the min and max temperature parameters.</p>