-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
  • 81,317
  • 8
  • 19
  • 49
Yasiru
  • 56
  • 1
  • 7

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
  • 81,317
  • 8
  • 19
  • 49
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
Yasiru
  • 56
  • 1
  • 7