袖扣显示空白

Cufflinks shows blank

我尝试导入财务数据并使用以下代码。 它运行良好,但在情节上只显示空白 canvas。 我缩小范围,发现问题出在袖扣上,因为单独使用 iplot(不使用 dataframe 仍然可以正常工作) enter image description here

import pandas as pd
import numpy as np
import datetime
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')
%matplotlib inline

start = datetime.datetime(2006, 1, 1)
end = datetime.datetime(2016, 1, 1)
# Bank of America
BAC = data.DataReader("BAC", 'yahoo', start, end)

# CitiGroup
C = data.DataReader("C", 'yahoo', start, end)

# Goldman Sachs
GS = data.DataReader("GS", 'yahoo', start, end)

# JPMorgan Chase
JPM = data.DataReader("JPM", 'yahoo', start, end)

# Morgan Stanley
MS = data.DataReader("MS", 'yahoo', start, end)

# Wells Fargo
WFC = data.DataReader("WFC", 'yahoo', start, end)

df = data.DataReader(['BAC', 'C', 'GS', 'JPM', 'MS', 'WFC'],'yahoo', start, end)

tickers = ['BAC', 'C', 'GS', 'JPM', 'MS', 'WFC']

bank_stocks = pd.concat([BAC, C, GS, JPM, MS, WFC],axis=1,keys=tickers)

# Optional Plotly Method Imports
import plotly
import cufflinks as cf
cf.go_offline()

bank_stocks.xs(key='Close',axis=1,level='Stock Info').iplot()

我认为图表没有显示是因为缺少多索引的名称。请在绘制图形的代码前添加如下代码。

bank_stocks.columns.names = ['Bank Ticker','Stock Info']

另外,可以添加以下代码作为缺少显示的原因。此函数需要在执行 iplot() 之前调用。另请参阅

def enable_plotly_in_cell():
    import IPython
    from plotly.offline import init_notebook_mode
    display(IPython.core.display.HTML('''
            <script src="/static/components/requirejs/require.js"></script>
    '''))
    init_notebook_mode( connected=False )

import plotly
import cufflinks as cf
cf.go_offline()
enable_plotly_in_cell()

bank_stocks.xs(key='Close', axis=1, level='Stock Info').iplot()