python画的图怎么保存

丫収衣菔 1个月前 已收到1个回答 举报

街痞野性 4星

共回答了445个问题采纳率:98.2% 评论

保存的方式有两种:

1、使用matplotlib画图保存方法:

首先,import头文件如下:

import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.pyplot import plot,savefig

画图:

fig, ax = plt.subplots(figsize=(12, 12)) ax.imshow(im, aspect='equal') #im是要显示的图像

保存图片:

savefig("D:/1.jpg")

展示图片:

plt.show()

2、turtle生成图片保存

代码示例如下:

from Tkinter import * from turtle import * import turtle forward(100) ts = turtle.getscreen() ts.getcanvas().postscript(file="duck.eps") #.eps文件即postscript脚本

以上就是python画图后如何保存的详细内容。

1小时前

25
可能相似的问题

热门问题推荐

Copyright © 2024 微短问答 All rights reserved. 粤ICP备2021119249号 站务邮箱 service@wdace.com