本文共 1458 字,大约阅读时间需要 4 分钟。
函数包名为:
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() 以上Bug是泛泛而谈,详细的Bug排查需要一步步探底。
转载地址:http://uoafk.baihongyu.com/