python数据分析二十:matplotlib保存图片

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_38788128/article/details/80804661
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from datetime import datetime

fig=plt.figure()

ax=fig.add_subplot(1,1,1)

rect=plt.Rectangle((0.2,0.75),0.4,0.15,color='k',alpha=0.3)
circ=plt.Circle((0.7,0.5),0.15,color='b',alpha=0.3)
pgon=plt.Polygon([[0.15,0.15],[0.36,0.4],[0.2,0.6]],color='g',alpha=0.5)

ax.add_patch(rect)
ax.add_patch(circ)
ax.add_patch(pgon)
'''
将图片保存
'''
plt.savefig('1.svg')

'''
保存为400DPI的PNG图片
'''
plt.savefig('2.png',dpi=400,bbox_inches='tight')

'''
写入流,web中动态生成文件
'''
# from io import StringIO
# buffer=StringIO()
# plt.savefig(buffer)
# plot_data=buffer.getvalue()

plt.show()





 

展开阅读全文

没有更多推荐了,返回首页