我试着用这段代码做一个条形图
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')
但是我得到了这个错误:
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):
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']:
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']
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
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.
有什么想法可以帮助我吗?
谢谢
最佳答案
需要注意错误中的traceback。在这种情况下,它比平时更有帮助。解决方案在这里给你:
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 key ,它与您的密码不同。
关于python - 带有 plotly 的基本条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39208680/