Pandas merging 2 DataFrames into one graph
<p>I am trying to plot two pandas dataframes. One dataframe needs to be displayed as a line graph and another as a scatter plot on the same graph.</p>

<p>This plots the first dataframe:</p>

<pre><code>line = pd.read_csv('nugt_daily.csv',parse_dates=['Date'])
line = line.sort_values(by='Date')
line.set_index('Date',inplace=True)
line['Close'].plot(figsize=(16, 12))
</code></pre>

<p>I want to plot the following dataframe on top of the previous graph - but as a scatter plot (rather than a line graph):</p>

<pre><code>points = pandas.read_csv('test_doc.csv')
points = points.sort_values(by='Date')
points.set_index('Date',inplace=True)
points.plot(figsize=(16, 12))
</code></pre>

<p>How can I achieve this? When I run the two codes one after the other, I see two separate graphs for each dataframe.</p>

<p>Use <code>return_type='axes'</code> to get <code>df1.scatterplot</code> to return a matplotlib Axes object. Then pass that axes to the second call to linegraph using <code>ax=ax</code>. This will cause both plots to be drawn on the same axes.</p>

<p>Try:</p>

<pre><code>ax = df1.plot()
df2.plot(ax=ax)
</code></pre>

python pandas numpy matplotlib