Building multiple lines in iPython / pandas Produces multiple graphs

I'm trying to think about the model of the matplotlib machine, but I get an error when trying to build several lines in one section. From what I understand, the following code should create a single graph with two lines:

import pandas as pd
import pandas.io.data as web
aapl = web.get_data_yahoo('AAPL', '1/1/2005')

# extract adjusted close
adj_close = aapl.loc[:, ['Adj Close']]

# 2 lines on one plot
hold(False)
adj_close.resample('M', how='min').plot()
adj_close.resample('M', how='max').plot()

In fact, I get three digits: first blank, and then two with one line each.

blank plotfirst plotsecond plot

Any idea what I am doing wrong or what settings on my system might be configured incorrectly?

+4
source share
1 answer

You can pre-create the axis object using the matplotlibs package pyplot, and then add graphs to this axis object:

import pandas as pd
import pandas.io.data as web
import matplotlib.pyplot as plt

aapl = web.get_data_yahoo('AAPL', '1/1/2005')

# extract adjusted close
adj_close = aapl.loc[:, ['Adj Close']]

# 2 lines on one plot
#hold(False)

fig, ax = plt.subplots(1, 1)
adj_close.resample('M', how='min').plot(ax=ax)
adj_close.resample('M', how='max').plot(ax=ax)

Plot example

mx2 DataFrame :

s1 = adj_close.resample('M', how='min')
s2 = adj_close.resample('M', how='max')
df = pd.concat([s1, s2], axis=1)
df.plot()
+8

All Articles