Cannot show the graphs on ipython notebook

一曲冷凌霜 提交于 2019-12-14 03:58:42

问题


I'm playing around ipython notebook and have a question.

I was trying to visualize the stock price and the trading volume in a graph. My code is:

import datetime
import pandas as pd
import pandas.io.data
from pandas import DataFrame    
import matplotlib.pyplot as plt
from matplotlib import style

# skipping some code to get stock prices

ax1= plt.subplot(2,1,1)
ax1.plot(df.Close,label="sp500")
ax1.plot(ma,label='50MA')
plt.legend()

ax2=plt.subplot(2,1,2, sharex = ax1)
ax2.plot(df['H-L'],label='H-L')
plt.show()

And I succeeded plotting with ipython console. However, I cannot plot with ipython notebook. It seems like ipython notebook does nothing and python launcher popping up forever. Do anyone have ideas what's going on here?


回答1:


try adding this line before your plotting code

%matplotlib inline

It tells the ipython notebook to display plots inilne



来源:https://stackoverflow.com/questions/27751261/cannot-show-the-graphs-on-ipython-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!