Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从EC2实例将matplotlib映像保存到S3存储桶_Matplotlib_Amazon S3_Amazon Ec2_Pyspark - Fatal编程技术网

从EC2实例将matplotlib映像保存到S3存储桶

从EC2实例将matplotlib映像保存到S3存储桶,matplotlib,amazon-s3,amazon-ec2,pyspark,Matplotlib,Amazon S3,Amazon Ec2,Pyspark,我正在尝试将matplotlib保存到AWS上的S3存储桶中。 我像这样使用savefig()函数: import matplotlib.pyplot as plt f = plt.figure() plt.plot(some figure) f.savefig("s3://bucketpath/foo.pdf", bbox_inches='tight') 但是我得到了路径未找到错误。 如果我不指定路径,它似乎可以正常工作,但我不知道它保存在哪里 我正在使用sagemak

我正在尝试将matplotlib保存到AWS上的S3存储桶中。 我像这样使用
savefig()
函数:

import matplotlib.pyplot as plt

f = plt.figure()
plt.plot(some figure)
f.savefig("s3://bucketpath/foo.pdf", bbox_inches='tight')
但是我得到了
路径未找到错误
。 如果我不指定路径,它似乎可以正常工作,但我不知道它保存在哪里

我正在使用sagemaker jupyterlab运行我的代码(在pyspark中),因此在一个EC2实例上运行。 有没有办法指定保存pdf的路径,就像将数据帧保存到S3存储桶时使用
write()
函数一样

我在这个网站上看到了这篇文章,但它是用于使用boto从本地客户端上传到云上的S3的。
有没有办法不使用aws访问键等直接将其保存到S3?

我在aws EMR上运行的Jupyter笔记本上遇到了类似的问题,当时我正试图将另一种二进制文件格式(png)保存到S3。我通过使用
s3fs
库与S3接口解决了这个问题

使用您的示例,它应该如下所示:

import io

import matplotlib.pyplot as plt
import s3fs

plt.plot(some figure)

img_data = io.BytesIO()
plt.savefig(img_data, format='pdf', bbox_inches='tight')
img_data.seek(0)

s3 = s3fs.S3FileSystem(anon=False)  # Uses default credentials
with s3.open('s3://bucketpath/foo.pdf', 'wb') as f:
    f.write(img_data.getbuffer())
我注意到您在Sagemaker JupyterLab上工作,但看看
s3fs
docs,我相信它也能工作


我的解决方案基于和

这在EC2中实际上不可能吗?