2017-08-08 42 views
0

我在python上使用plotly生成图表,突然间我开始在运行过程中遇到错误。将图表保存为图像时似乎发生错误。 这让我这个错误电话是:py.image.save_as()函数粉碎代码

py.image.save_as(fig, pic_name) 

那就是使调用该函数:

def bar_chart_general(tags, malicious, benign, pic_name, xTitle, yTitle, Title): 
    data1 = go.Bar(x=tags, y=benign, name='Benign') 
    data2 = go.Bar(x=tags, y=malicious, name='Malicious') 
    data = [data1, data2] 
    annotations = [dict(x=xi, y=yi,text=str(yi), xanchor='right', yanchor='bottom', showarrow=False,) for xi, yi in zip(tags, benign)] +\ 
       [dict(x=xi, y=yi,text=str(yi), xanchor='left', yanchor='bottom', showarrow=False,) for xi, yi in zip(tags, malicious)] 
    layout = go.Layout(xaxis=go.XAxis(title=xTitle), yaxis=go.YAxis(title=yTitle), annotations=annotations) 
    fig = go.Figure(data=data, layout=layout) 
    py.image.save_as(fig, pic_name) 
    return 

这里我调用该函数:

# downloads per source 
df = pd.read_csv("input_csv/downloads_per_source.csv") 
bar_chart_general(df["source"], df["malicious"], df["benign"], "output_charts/downloads_per_source.png", 'Source', 'Downloads', 
       'Downloads per Source') 

那就是我得到的错误:

C:\Python27\python.exe C:/Users/zionina/PycharmProjects/Charts/ChartsCreator.py 
Traceback (most recent call last): 
    File "C:/Users/zionina/PycharmProjects/Charts/ChartsCreator.py", line 130, in <module> 
'Downloads per Source') 
    File "C:/Users/zionina/PycharmProjects/Charts/ChartsCreator.py", line 81, in bar_chart_general 
    py.image.save_as(fig, pic_name) 
    File "C:\Python27\lib\site-packages\plotly\plotly\plotly.py", line 831, in save_as 
    img = cls.get(figure_or_data, format, width, height, scale) 
    File "C:\Python27\lib\site-packages\plotly\plotly\plotly.py", line 744, in get 
    response = v2.images.create(payload) 
    File "C:\Python27\lib\site-packages\plotly\api\v2\images.py", line 18, in create 
    return request('post', url, json=body) 
    File "C:\Python27\lib\site-packages\plotly\api\v2\utils.py", line 153, in request 
    validate_response(response) 
    File "C:\Python27\lib\site-packages\plotly\api\v2\utils.py", line 79, in validate_response 
    raise exceptions.PlotlyRequestError(message, status_code, content) 
plotly.exceptions.PlotlyRequestError: Request was throttled. Expected available in 66964.0 seconds. 

感谢任何人可以帮助

回答

0

问题是AIP密钥。我改变了钥匙,它再次运作