Python -Two figures in one plot
<p>I have two python plot functions:  </p>

<pre><code>def plotData(data):
    fig, ax = plt.subplots()
    results_accepted = data[data['accepted'] == 1]
    results_rejected = data[data['accepted'] == 0]
    ax.scatter(results_accepted['exam1'], results_accepted['exam2'], marker='+', c='b', s=40)
    ax.scatter(results_rejected['exam1'], results_rejected['exam2'], marker='o', c='r', s=30)
    ax.set_xlabel('Exam 1 score')
    ax.set_ylabel('Exam 2 score')
    return ax
</code></pre>

<p>And second function is:</p>

<pre><code>def plot_boundry(theta,x):
    """
    """
    plt.figure(1)
    px = np.array([x[:, 1].min() - 2, x[:, 1].max() + 2])
    py = (-1 / theta[2]) * (theta[1] * px + theta[0])
    fig, ax = plt.subplots()
    ax.plot(px, py)
    return ax
</code></pre>

<p>And i am calling both :</p>

<pre><code>#####PLOT ######
ax = plotData(df)
ax = plot_boundry(opt_theta, x)
</code></pre>

<p>I get 2 separate plots:<br>
<a href="http://i.stack.imgur.com/j60xl.png" rel="nofollow"><img src="http://i.stack.imgur.com/j60xl.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/GszfC.png" rel="nofollow"><img src="http://i.stack.imgur.com/GszfC.png" alt="enter image description here"></a></p>

<p>I got 2 separate picture.How Do I add two plot into one.
Both the plot should be one plot.</p>

<p>It depends what you want exactly:</p>

<ol>
<li><p>If you want the two figures overlayed, then you can call <a href="http://stackoverflow.com/questions/21465988/python-equivalent-to-hold-on-in-matlab"><code>hold</code></a><code>(True)</code> after the first, then plot the second, then call <code>hold(False)</code>.</p></li>
<li><p>If you want the two figures in a single figure, but side by side (or one over the other), then you can use <a href="http://matplotlib.org/examples/pylab_examples/subplot_demo.html" rel="nofollow"><code>subplot</code></a>. E.g., call <code>subplot(2, 1, 1)</code> before plotting the first, then <code>subplot(2, 1, 2)</code> before the second.</p></li>
</ol>

python matplotlib