Python3 matplotlib 将图片转华为png格式图片数据

from io import BytesIO
import base64
import numpy as np
import matplotlib.pyplot as plt
from io import BytesIO # 内存中构建

x = np.arange(100)
y = np.sin(x)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)

save_file = BytesIO()
plt.savefig(save_file, format='png')

save_file_base64 = base64.b64encode(save_file.getvalue()).decode('utf8')
png_data='data:image/png;base64,'+save_file_base64
print(png_data)

发布了35 篇原创文章 · 获赞 7 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/hekf2010/article/details/104663058
今日推荐