我在python上使用plotly生成图表,突然间我开始在运行期间出错。将图表另存为图像时似乎发生了错误。 给我这个错误的电话是:
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 :(得分:0)
问题是AIP密钥。我更改了密钥并再次运行