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)