我得到:chart_studio.exceptions.PlotlyRequestError:未提供身份验证凭据

问题描述 投票:0回答:5

我在本地(在我的电脑上)工作,只是测试和学习 PLOTLY 3.7.5。 anaconda env 处于活动状态。 代码示例由plotly

给出

代码:

import plotly.plotly as py  # Here all begins (Look)
# import chart_studio.plotly as py  # inted of the line bellow (optional to  try)
import plotly.graph_objs as go
import pandas as pd
from datetime import datetime

if __name__ == '__main__':
    df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
    trace = go.Ohlc(x=df['Date'],
                    open=df['AAPL.Open'],
                    high=df['AAPL.High'],
                    low=df['AAPL.Low'],
                    close=df['AAPL.Close'])
    data = [trace]
    py.iplot(data, filename='simple_ohlc')

注意(看):我收到警告错误:

'请安装chart-studio包并使用chart_studio.plotly模块。'

python plotly ohlc
5个回答
16
投票

您需要plotly的离线模式来避免身份验证 - 按照https://stackoverflow.com/a/44694854/1021819,而是这样做:

from plotly.offline import iplot

4
投票

在点击 iplot 之前使用下面的代码行

cf.go_offline() #will make cufflinks offline
cf.set_config_file(offline=False, world_readable=True)

2
投票
import pandas as pd
import numpy as np
%matplotlib inline
import plotly.graph_objs as go
from  plotly.offline import plot
import chart_studio.plotly as py
import cufflinks as cf
cf.go_offline()
from plotly.offline import download_plotlyjs, init_notebook_mode, plot,iplot
init_notebook_mode(connected='true')
df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
df.head()
df.iplot(kind='box')

0
投票

启动 Plotly 和袖扣部分的基础知识:

import pandas as pd
import numpy as np  
%matplotlib inline  
from plotly import __version__ 
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
init_notebook_mode(connected=True)
cf.go_offline()

-3
投票

自动调用下面这两个库问题就解决了

import chart_studio.plotly as py

© www.soinside.com 2019 - 2024. All rights reserved.