除其他外,我正在使用 绘制图matplotlib,我想立即将其存储为 S3 对象。
根据this和this other question以及精美手册中提供的答案,我需要S3.Object.put()将我的数据移动到AWS中,并且程序应该遵循
from matplotlib import pyplot as plt
import numpy as np
import boto3
import io
# plot something
fig, ax = plt.subplots()
x = np.linspace(0, 3*np.pi, 500)
a = ax.plot(x, np.sin(x**2))
# get image data, cf. /sf/answers/3156988691/
buf = io.BytesIO()
fig.savefig(buf, format="png")
buf.seek(0)
image = buf.read()
# put the image into S3
s3 = boto3.resource('s3', aws_access_key_id=awskey, aws_secret_access_key=awssecret)
s3.Object(mybucket, mykey).put(ACL='public-read', Body=image)
Run Code Online (Sandbox Code Playgroud)
但是,我最终得到了一个内容长度为零的新 S3 对象。
下面给了我一个内容长度为 6 …
我用python编写了一个程序,当我打开太多的tempfile时,我会得到一个例外:太多的打开文件......然后我发现windows OS或C运行时有文件句柄限制,所以,我改变我的程序使用StringIO(),但仍然不知道StringIO是否也是有限的?
我有一个在 Jupyter 笔记本中工作的 wordcloud 生成器。我想为它构建一个前端,以便您可以将文本粘贴到文本框中,单击提交并显示 wordcloud。基本上这个家伙在这里做了什么。
我正在寻求一些帮助来修改我的代码,以便它不会在 Jupyter notebook 中显示 wordcloud,而是在 HTML 页面上呈现 wordcloud 的图像。我正在使用 Django 来构建前端。
这是我在 Jupyter 笔记本中生成 wordcloud 图像的代码。
from wordcloud import WordCloud
from PIL import Image
import matplotlib.pyplot as plt
import nltk
# sun only once -> nltk.download('punkt')
#nltk.download('wordnet') -> only do this once
from nltk.stem.porter import PorterStemmer
from nltk.stem import WordNetLemmatizer
ps = PorterStemmer()
wnl = WordNetLemmatizer()
def stem(string):
stemstring = ""
nltk_tokens = nltk.word_tokenize(string)
for word in nltk_tokens:
if word …Run Code Online (Sandbox Code Playgroud) matplotlib ×2
python ×2
amazon-s3 ×1
boto3 ×1
django ×1
django-forms ×1
django-views ×1
io ×1
python-3.x ×1