5

Can you save a graph to s3 without saving the file locally first?

from boto.s3.connection import S3Connection
from boto.s3.key import Key

k = Key(bucket)
k.key = "mykey"

plt.savefig(k.key) //??
user2954587
  • 4,661
  • 6
  • 43
  • 101
  • 1
    Possible duplicate of [python - uploading a plot from memory to s3 using matplotlib and boto](http://stackoverflow.com/questions/31485660/python-uploading-a-plot-from-memory-to-s3-using-matplotlib-and-boto) – Aidan Feldman Dec 04 '16 at 22:47

1 Answers1

0
BUCKET_NAME = 'enter your bucket name'
KEY = 'enter full path where to store the image'

df = pd.read_csv('./gene_expression.csv')
df.hist(by='Cancer Present', figsize=[12, 8], bins=15)
img_data = io.BytesIO()
plt.savefig(img_data, format='png')
img_data.seek(0)

s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET_NAME)
bucket.put_object(Body=img_data, ContentType='image/png', Key=KEY)
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 11 '23 at 02:31