简体   繁体   English

带有 plotly 的基本条形图

[英]Basic Bar Chart with plotly

I try to do a bar charts, with this code我尝试使用此代码制作条形图

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')

But I got this error :但我收到了这个错误:

 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

in iplot(figure_or_data, **plot_options) 149 if 'auto_open' not in plot_options: 150 plot_options['auto_open'] = False --> 151 url = plot(figure_or_data, **plot_options) 152 153 if isinstance(figure_or_data, dict):在 iplot(figure_or_data, **plot_options) 149 如果 'auto_open' 不在 plot_options: 150 plot_options['auto_open'] = False --> 151 url = plot(figure_or_data, **plot_options) 152 153 if isinstance(figure_or_data, :

 C:\\Users\\Demonstrator\\Anaconda3\\lib\\site-packages\\plotly\\plotly\\plotly.py

in plot(figure_or_data, validate, **plot_options) 239 240 plot_options = _plot_option_logic(plot_options) --> 241 res = _send_to_plotly(figure, **plot_options) 242 if res['error'] == '': 243 if plot_options['auto_open']:在 plot(figure_or_data, validate, **plot_options) 239 240 plot_options = _plot_option_logic(plot_options) --> 241 res = _send_to_plotly(figure, **plot_options) 242 if res['error'] == '': 243 if plot_options[ 'auto_open']:

 C:\\Users\\Demonstrator\\Anaconda3\\lib\\site-packages\\plotly\\plotly\\plotly.py

in _send_to_plotly(figure, **plot_options) 1401 cls=utils.PlotlyJSONEncoder) 1402 credentials = get_credentials() -> 1403 validate_credentials(credentials) 1404 username = credentials['username'] 1405 api_key = credentials['api_key']在 _send_to_plotly(figure, **plot_options) 1401 cls=utils.PlotlyJSONEncoder) 1402 凭证 = get_credentials() -> 1403 validate_credentials(credentials) 1404 用户名 = 凭证['用户名'] 1405 [api_key] 凭证

C:\\Users\\Demonstrator\\Anaconda3\\lib\\site-packages\\plotly\\plotly\\plotly.py

in validate_credentials(credentials) 1350 api_key = credentials.get('api_key') 1351 if not username or not api_key: -> 1352 raise exceptions.PlotlyLocalCredentialsError() 1353 1354在 validate_credentials(credentials) 1350 api_key = credentials.get('api_key') 1351 如果不是用户名或不是 api_key:-> 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.

Any idea to help me please?有什么想法可以帮助我吗?

Thank you谢谢

You need to pay attention to the traceback in the error.您需要注意错误中的回溯。 In this case, it's even more helpful than usual.在这种情况下,它比平时更有帮助。 The solution is given to you here:在此为您提供解决方案:

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. 

So, enter your credentials used when you signed up to the site before you attempt to make a plot.因此,在尝试制作情节之前,请输入您在注册该网站时使用的凭据。 You may have to sign in in a web browser and request for an API key to be generated, it is not the same as your password.您可能需要登录 Web 浏览器并请求生成 API 密钥,它与您的密码不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM