Home  >  Article  >  Backend Development  >  How to save the picture after drawing in python

How to save the picture after drawing in python

尚
Original
2019-07-05 09:46:2420534browse

How to save the picture after drawing in python

1. How to save drawing using matplotlib:

First, import the header file as follows:

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

Drawing:

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

Save the picture:

savefig("D:/1.jpg")

Display the picture:

plt.show()

2. Save the turtle generated picture

The code example is as follows:

from Tkinter import *
from turtle import *
import turtle


forward(100)
ts = turtle.getscreen()

ts.getcanvas().postscript(file="duck.eps") #.eps文件即postscript脚本

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to save the picture after drawing in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn