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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章