I\'ve been following \'python for data analysis\'. On pg. 345, you get to this code to plot returns across a variety of stocks. However, the plotting function does not work for
I found this error to be due to a combination of:
%matplotlib inline
magic in ipythonSo the following will fail on a newly started kernel in an ipython notebook:
# fails
import matplotlib.pylab
%matplotlib inline
import pandas
ser = pandas.Series(range(10), pandas.date_range(end='2014-01-01', periods=10))
ser.plot()
The best way to solve this is to move the magic up to the top:
# succeeds
%matplotlib inline # moved up
import matplotlib.pylab
import pandas
ser = pandas.Series(range(10), pandas.date_range(end='2014-01-01', periods=10))
ser.plot()
However the problem also goes away if you pass the series to a matplotlib
plotting method, don't use a date index, or simply don't import the matplotlib.pylab
module.