我尝试用这段代码做条形图
import plotly.plotly as py
import plotly.graph_objs as go
data = [go.Bar(
x=['giraffes', 'orangutans', 'monkeys'],
y=[20, 14, 23]
)]
py.iplot(data, filename='basic-bar')
但我收到了这个错误:
iplot中的PlotlyLocalCredentialsError Traceback (most recent call last) <ipython-input-42-9eae40f28f37> in <module>() 3 y=[20, 14, 23] 4 )] ----> 5 py.iplot(data, filename='basic-bar') C:\Users\Demonstrator\Anaconda3\lib\site-packages\plotly\plotly\plotly.py
(figure_or_data,** plot_options) 149如果&#39; auto_open&#39;不在plot_options中: 150 plot_options [&#39; auto_open&#39;] = False - &GT; 151 url = plot(figure_or_data,** plot_options) 152 153 if isinstance(figure_or_data,dict):
情节中的C:\Users\Demonstrator\Anaconda3\lib\site-packages\plotly\plotly\plotly.py
(figure_or_data,validate,** plot_options) 239 240 plot_options = _plot_option_logic(plot_options) - &GT; 241 res = _send_to_plotly(图,** plot_options) 如果res [&#39;错误&#39;] ==&#39;&#39;: 243如果plot_options [&#39; auto_open&#39;]:
_send_to_plotly中的C:\Users\Demonstrator\Anaconda3\lib\site-packages\plotly\plotly\plotly.py
(图,** plot_options) 1401 cls = utils.PlotlyJSONEncoder) 1402凭据= get_credentials() - &GT; 1403 validate_credentials(凭据) 1404用户名=凭据[&#39;用户名&#39;] 1405 api_key =凭证[&#39; api_key&#39;]
C:\Users\Demonstrator\Anaconda3\lib\site-packages\plotly\plotly\plotly.py
在validate_credentials(凭据)中 1350 api_key = credentials.get(&#39; api_key&#39;) 1351如果不是用户名或不是api_key: - &GT; 1352引发异常.PlotlyLocalCredentialsError() 1353 1354
PlotlyLocalCredentialsError: Couldn't find a 'username', 'api-key' pair for you on your local machine. To sign in temporarily (until you stop running Python), run: >>> import plotly.plotly as py >>> py.sign_in('username', 'api_key') Even better, save your credentials permanently using the 'tools' module: >>> import plotly.tools as tls >>> tls.set_credentials_file(username='username', api_key='api-key') For more help, see https://plot.ly/python.
有什么好主意帮我吗?
谢谢
答案 0 :(得分:3)
您需要注意错误中的回溯。在这种情况下,它比平时更有帮助。解决方案在这里给你:
PlotlyLocalCredentialsError:
Couldn't find a 'username', 'api-key' pair for you on your local machine. To sign in temporarily (until you stop running Python), run:
>>> import plotly.plotly as py
>>> py.sign_in('username', 'api_key')
Even better, save your credentials permanently using the 'tools' module:
>>> import plotly.tools as tls
>>> tls.set_credentials_file(username='username', api_key='api-key')
For more help, see https://plot.ly/python.
因此,在尝试制作绘图之前,请输入您在注册网站时使用的凭据。您可能必须在Web浏览器中登录并请求生成API密钥,它与您的密码不同。