2017-07-30 98 views
1

我是新来的编码,并试图通过代码来理解Quantopian的演讲,但是当我在PyCharm中运行代码时,没有输出。有人可以告诉我发生了什么事,并告诉我如何解决这个问题?熊猫不绘制代码。

下面是我的一段代码(2.7.13):

import numpy as np 
import pandas as pd 

import statsmodels 
import statsmodels.api as sm 
from statsmodels.tsa.stattools import coint 
# just set the seed for the random number generator 
np.random.seed(107) 

import matplotlib.pyplot as plt 

X_returns = np.random.normal(0, 1, 100) # Generate the daily returns 
# sum them and shift all the prices up into a reasonable range 
X = pd.Series(np.cumsum(X_returns), name='X') + 50 
X.plot(); 

唯一的输出,当我运行这一点,就是:

+5

看来你最终需要'plt.show()'。 – jezrael

+0

@jezrael:非常感谢。这似乎解决了这个问题。不知道这个:) – boametaphysica

+0

可能不需要';'尽管尽管 – Hatshepsut

回答

1

只需添加PLT “退出代码为0进程结束” .show()结尾:

import numpy as np 
import pandas as pd 

import statsmodels 
import statsmodels.api as sm 
from statsmodels.tsa.stattools import coint 
# just set the seed for the random number generator 
np.random.seed(107) 

import matplotlib.pyplot as plt 

X_returns = np.random.normal(0, 1, 100) # Generate the daily returns 
# sum them and shift all the prices up into a reasonable range 
X = pd.Series(np.cumsum(X_returns), name='X') + 50 
X.plot() 
plt.show()