【发布时间】:2015-06-30 01:09:56
【问题描述】:
下午好,
我是这里的新手。我正在尝试绘制价差收益的直方图,但是,matplotlib 拒绝绘制直方图而没有相应的错误。你能解释一下,我在代码中的错误在哪里。谢谢。
import numpy as np
import pandas as pd
import pandas.io.data as web
import matplotlib.pyplot as plt
goog = web.DataReader('GOOG', data_source='google',
start='3/14/2009', end='4/14/2014')
goog.tail()
goog['Ret'] = ((goog['Close'] - goog['Close'].shift(1)) /
goog['Close'].shift(1))*100
goog[['Close','Ret']].tail()
WY = web.DataReader('WY', data_source='google',
start='3/14/2009', end='4/14/2014')
WY.tail()
WY['Ret'] = ((WY['Close'] - WY['Close'].shift(1)) /WY['Close'].shift(1))*100
WY[['Close','Ret']].tail()
a=goog['Ret']
a = a[~np.isnan(a)]
b=WY['Ret']
b = b[~np.isnan(b)]
%matplotlib inline
my_array = [i/m for i,m in zip(a, b)]
plt.hist(my_array, bins=25)
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('value')
plt.ylabel('frequency')
plt.title('Histogram')
【问题讨论】:
-
我怀疑这是因为您需要告诉 matplotlib 向您展示您的身材。尝试在底部添加
plt.show()?
标签: python matplotlib plot histogram