posted on 2023-05-03 20:56 read(782) comment(0) like(26) collect(3)
plt.show()展示图片的时候,截图进行保存,图片不是多么清晰
如何保存高清图也是一知识点
函数包名:import matplotlib.pyplot as plt
主要功能:保存绘制数据后创建的图形。使用此方法可以将创建的图形保存
函数源码:(根据需要进行选择)
savefig(fname, dpi=None, facecolor=’w’, edgecolor=’w’, orientation=’portrait’, papertype=None,
format=None, transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None, metadata=None)
参数解释:
参数 | 描述 |
---|---|
fname | 指定格式图片或者指定文件位置 |
dpi | 画质 |
facecolor 和 edgecolor | 默认为白色 |
Orientation | 横向或者纵向 |
papertype | 纸张类型 |
format | 如png、pdf |
transparent | 图片背景透明 |
bbox_inches | 图表多余的空白区去除 |
pad_inches | 保存图形周围填充 |
正常保存:plt.savefig("xx.png")
,也可以svg的格式进行保存
保存的时候需要plt.show()在plt.savefig()之后,顺序颠倒会出现图片为空白。
当前文件保存:
注意事项:
要把所有的参数用上,可以用在直方图上
import matplotlib.pyplot as plt
x =[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
plt.hist(x)
plt.savefig("squares1.png",
bbox_inches ="tight",
pad_inches = 1,
transparent = True,
facecolor ="g",
edgecolor ='w',
orientation ='landscape')
plt.show()
截图如下:
Author:evilangel
link:http://www.pythonblackhole.com/blog/article/248/4874c4ea5b08d0366015/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!