<div dir="ltr"><div><div><div>You might want to check out my Anatomy of Matplotlib tutorial: <a href="https://github.com/matplotlib/AnatomyOfMatplotlib">https://github.com/matplotlib/AnatomyOfMatplotlib</a><br><br></div>You can use the Jupyter notebooks and follow along with the recordings available on YouTube: <a href="https://www.youtube.com/watch?v=rARMKS8jE9g">https://www.youtube.com/watch?v=rARMKS8jE9g</a> (Scipy 2017) and <a href="https://www.youtube.com/watch?v=MKucn8NtVeI">https://www.youtube.com/watch?v=MKucn8NtVeI</a> (Scipy 2015 - which covered more, but spent less time on each aspect).<cite class="gmail-_Rm"></cite><br><br></div><div>There is also a book, "Mastering Matplotlib", which goes into deep depths with respect to the API and logic behind the library: <a href="https://www.amazon.com/Mastering-matplotlib-Duncan-M-McGreggor/dp/1783987545">https://www.amazon.com/Mastering-matplotlib-Duncan-M-McGreggor/dp/1783987545</a><br><br></div><div>I hope that helps!<br></div><div>Ben Root<br><br></div><cite class="gmail-_Rm"></cite></div><cite class="gmail-_Rm"></cite></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 27, 2017 at 8:37 AM, William Ray Wing <span dir="ltr"><<a href="mailto:wrw@mac.com" target="_blank">wrw@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Sep 26, 2017, at 6:20 PM, Ryan May <<a href="mailto:rmay31@gmail.com" target="_blank">rmay31@gmail.com</a>> wrote:</div><br class="m_3471630283204383576Apple-interchange-newline"><div><div dir="ltr">William,<div><br></div><div>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><br></div></div></div></blockquote><div><br></div></span><div>Thanks, that did it. Very grateful.</div><div><br></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></div><div>Thanks,</div><div>Bill</div><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><div><span style="font-size:12.800000190734863px">import numpy as np, matplotlib.pyplot as plt</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">def problem(xdata, ydata, i):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> color_dic = {1: "red", 2: "green", 3: "blue", 4: "cyan"}</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> fig1, ax1 = plt.subplots()</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> ax1.plot(xdata, ydata, linestyle = '-', color = color_dic[i])</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> fig1.savefig('Plot for run_num ' + str(i))</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> return</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">def problem_alt(xdata, ydata, i):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> return</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">t = np.arange(0.0, 2.0, 0.01)</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">fig2, ax2 = plt.subplots()</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">for i in range(0,4):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> i = i+1</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> problem(t, np.sin(i*np.pi*3*t), i)</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> problem_alt(t, np.sin(i*np.pi*3*t), i)</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> ax2.set_xlim(xmin = 0.0, xmax = 20.0)</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px"> ax2.plot((t+i*3), np.sin(i*np.pi*3*(t+i*3)))</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">fig2.savefig("Global Plot")</span><br style="font-size:12.800000190734863px"></div><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">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><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">Ryan</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 26, 2017 at 3:04 PM, William Ray Wing <span dir="ltr"><<a href="mailto:wrw@mac.com" target="_blank">wrw@mac.com</a>></span> wrote:<br><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>
<br>
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>
<br>
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>
<br>
Thanks,<br>
Bill Wing<br>
<br>
#! /usr/bin/env python<br>
# -*- coding: utf-8 -*-<br>
#<br>
# A simple skeleton of the program to work out the plotting problem<br>
#<br>
import numpy as np, matplotlib.pyplot as plt<br>
#<br>
# skeleton subroutines<br>
#<br>
<br>
def problem(xdata, ydata, i):<br>
color_dic = {1: "red", 2: "green", 3: "blue", 4: "cyan"}<br>
plt.figure(1)<br>
fig1, ax1 = plt.subplots()<br>
plt.subplot()<br>
plt.plot(xdata, ydata, linestyle = '-', color = color_dic[i])<br>
plt.savefig('Plot for run_num ' + str(i))<br>
return<br>
<br>
def problem_alt(xdata, ydata, i):<br>
return<br>
<br>
<br>
t = np.arange(0.0, 2.0, 0.01)<br>
plt.figure(2)<br>
fig2, ax2 = plt.subplots()<br>
<br>
for i in range(0,4):<br>
i = i+1<br>
problem(t, np.sin(i*np.pi*3*t), i)<br>
problem_alt(t, np.sin(i*np.pi*3*t), i)<br>
ax2.set_xlim(xmin = 0.0, xmax = 20.0)<br>
plt.subplot()<br>
plt.plot((t+i*3), np.sin(i*np.pi*3*(t+i*3)))<br>
<br>
plt.savefig("Global Plot")<br>
<br>
______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/matplotlib-users</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_3471630283204383576gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Ryan May<br><br></div></div></div>
</div>
</div></blockquote></div></div></div><br></div><br>______________________________<wbr>_________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/matplotlib-<wbr>users</a><br>
<br></blockquote></div><br></div>