<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 26, 2017, at 6:20 PM, Ryan May <<a href="mailto:rmay31@gmail.com" class="">rmay31@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">William,<div class=""><br class=""></div><div class="">Don't use plt to call all of the methods, but directly use them off of the Figure (e.g. fig1) and Axes (e.g. ax1) instances you create:</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Thanks, that did it.  Very grateful.</div><div><br class=""></div><div>Parenthetically, I wish there were a matplotlib book that explained the underlying logic of mil plotting.  Every one I’ve looked into so far is full of specific cookbook examples, but they don’t explain what the various calls really do, what order they need to be called in (and why), and how they affect each other.  Cookbooks are fine for doing things by rote, but they don’t provide understanding. If anyone on this list knows of such a book, I’d really appreciate hearing.</div><div><br class=""></div><div>Thanks,</div><div>Bill</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><span style="font-size:12.800000190734863px" class="">import numpy as np, matplotlib.pyplot as plt</span><br style="font-size:12.800000190734863px" class=""><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">def problem(xdata, ydata, i):</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    color_dic = {1: "red", 2: "green", 3: "blue", 4: "cyan"}</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    fig1, ax1 = plt.subplots()</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    ax1.plot(xdata, ydata, linestyle = '-', color = color_dic[i])</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    fig1.savefig('Plot for run_num ' + str(i))</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    return</span><br style="font-size:12.800000190734863px" class=""><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">def problem_alt(xdata, ydata, i):</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    return</span><br style="font-size:12.800000190734863px" class=""><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">t = np.arange(0.0, 2.0, 0.01)</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">fig2, ax2 = plt.subplots()</span><br style="font-size:12.800000190734863px" class=""><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">for i in range(0,4):</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    i = i+1</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    problem(t, np.sin(i*np.pi*3*t), i)</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    problem_alt(t, np.sin(i*np.pi*3*t), i)</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    ax2.set_xlim(xmin = 0.0, xmax = 20.0)</span><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">    ax2.plot((t+i*3), np.sin(i*np.pi*3*(t+i*3)))</span><br style="font-size:12.800000190734863px" class=""><br style="font-size:12.800000190734863px" class=""><span style="font-size:12.800000190734863px" class="">fig2.savefig("Global Plot")</span><br style="font-size:12.800000190734863px" class=""></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">At least, I think that's what you're going for. Note I removed some extra calls to figure() and subplot() that I don't think were helping you.</span></div><div class=""><span style="font-size:12.800000190734863px" class=""><br class=""></span></div><div class=""><span style="font-size:12.800000190734863px" class="">Ryan</span></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Sep 26, 2017 at 3:04 PM, William Ray Wing <span dir="ltr" class=""><<a href="mailto:wrw@mac.com" target="_blank" class="">wrw@mac.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Below is a simplified version of a much more elaborate analysis code, but it will illustrate the problem I’m having.  What I want to do is repetitively call an analysis function from my main code and plot the results of that analysis (a curve fit, although thats immaterial here) while in that function.  Back in the main code, I want to plot the results of all the curve fits on a single plot.  They share a common x axis, but appear at different points along it.  What seems to be happening is that the gets set in the function, and doesn’t get set back in the main code.<br class="">
<br class="">
Note that there are two versions of the “problem” function, problem and problem_alt.  If you change the main code (move the #), you get the plot I want at the end of the main.<br class="">
<br class="">
There must be something I can call or set to recover the settings associated with figure(2), but I can’t seem to figure it out.  Any help would be appreciated.<br class="">
<br class="">
Thanks,<br class="">
Bill Wing<br class="">
<br class="">
#! /usr/bin/env python<br class="">
# -*- coding: utf-8 -*-<br class="">
#<br class="">
#   A simple skeleton of the program to work out the plotting problem<br class="">
#<br class="">
import numpy as np, matplotlib.pyplot as plt<br class="">
#<br class="">
# skeleton subroutines<br class="">
#<br class="">
<br class="">
def problem(xdata, ydata, i):<br class="">
    color_dic = {1: "red", 2: "green", 3: "blue", 4: "cyan"}<br class="">
    plt.figure(1)<br class="">
    fig1, ax1 = plt.subplots()<br class="">
    plt.subplot()<br class="">
    plt.plot(xdata, ydata, linestyle = '-', color = color_dic[i])<br class="">
    plt.savefig('Plot for run_num ' + str(i))<br class="">
    return<br class="">
<br class="">
def problem_alt(xdata, ydata, i):<br class="">
    return<br class="">
<br class="">
<br class="">
t = np.arange(0.0, 2.0, 0.01)<br class="">
plt.figure(2)<br class="">
fig2, ax2 = plt.subplots()<br class="">
<br class="">
for i in range(0,4):<br class="">
    i = i+1<br class="">
    problem(t, np.sin(i*np.pi*3*t), i)<br class="">
    problem_alt(t, np.sin(i*np.pi*3*t), i)<br class="">
    ax2.set_xlim(xmin = 0.0, xmax = 20.0)<br class="">
    plt.subplot()<br class="">
    plt.plot((t+i*3), np.sin(i*np.pi*3*(t+i*3)))<br class="">
<br class="">
plt.savefig("Global Plot")<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
Matplotlib-users mailing list<br class="">
<a href="mailto:Matplotlib-users@python.org" class="">Matplotlib-users@python.org</a><br class="">
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank" class="">https://mail.python.org/<wbr class="">mailman/listinfo/matplotlib-<wbr class="">users</a><br class="">
</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class="">Ryan May<br class=""><br class=""></div></div></div>
</div>
</div></blockquote></div><br class=""></body></html>