Scatter and Hist in one subplot in Python
<p>Here is code</p>

<pre><code>    df = pd.DataFrame(3 * np.random.rand(4, 2), columns=['a', 'b'])
    plt.subplot(121)
    df["a"].plot.box()
    plt.subplot(122)
    df.plot.scatter(x="a", y="b")
    plt.show()
</code></pre>

<p>Output comes in two different windows as follows:-</p>

<p>Figure 1
<a href="https://i.stack.imgur.com/OFZeu.png" rel="nofollow"><img src="https://i.stack.imgur.com/OFZeu.png" alt="Figure 1"></a></p>

<p>Figure 2
<a href="https://i.stack.imgur.com/yjYPP.png" rel="nofollow"><img src="https://i.stack.imgur.com/yjYPP.png" alt="Figure 2"></a></p>

<p>Although both should come in one window. Any advice where is mistake</p>

<p>You need to specify which axis to draw on when you call <code>scatter</code>. This can be done by passing an <code>ax =</code> argument to the plotting function:</p>

<pre><code>df = pd.DataFrame(3 * np.random.rand(4, 2), columns=['a', 'b'])
plt.subplot(121)
df["a"].plot.box()
ax = plt.subplot(122)
df.plot.scatter(x="a", y="b", ax = ax)
plt.show()
</code></pre>

python pandas matplotlib subplot