add a subplot to the plot produced by a previous function
<p>I've written a function that reads data from a csv file and plots it. Now I need to add a subplot with another part of the data from the same file, so I've tried to write a function that calls the first function and adds a subplot. When I do this, I get the two to show up as different figures. How can I suppress this and make both of them show in the same figure?</p>

<p>Here is a mockup of my code:</p>

<pre><code>def timex(h_ratio = [3, 1]):

    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib.gridspec as gridspec

    total_height = h_ratio[0] + h_ratio[1]
    gs = gridspec.GridSpec(total_height, 1)

    time = [1, 2, 3, 4, 5]
    x = [1, 2, 3, 4, 5]
    y = [1, 1, 1, 1, 1]

    ax1 = plt.subplot(gs[:h_ratio[0], :])
    plt.plot(time, x)
    plot = plt.gcf
    plt.show()

    return time, x, y, plot, gs, h_ratio

def timeyx():
    import matplotlib.pyplot as plt
    import matplotlib.gridspec as gridspec

    time, x, y, plot, gs, h_ratio = timex(h_ratio = [3, 1])
    ax2 = plt.subplot(gs[h_ratio[1], :])
    plt.plot(time, y) 
    plt.show()

timeyx()
</code></pre>

<p>I realize that I have two plt.show() statements, but if I remove one that figure will not show at all. </p>