-2

I have used plt.plot(plot1['x'], plot1['y']) to produce a plot from my "plot1" dataset.

I want to get a file like object from this plot how can I get it done?

Here is the full code:

enter image description here

mozway
  • 194,879
  • 13
  • 39
  • 75
Yas
  • 68
  • 2
  • 8

2 Answers2

1

So, it looks like you want to save your plot as a format that can be copied in instant messaging:

import io, base64
picture = io.BytesIO()
plt.savefig(picture, format='png')
picture.seek(0)
picture_b64 = base64.b64encode(picture.read())
mozway
  • 194,879
  • 13
  • 39
  • 75
0

Solution,

import io

buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
file = discord.File(buf, "image.png")
buf.close()
return file #  or do anything with the file
Yas
  • 68
  • 2
  • 8