matplotlib的一些操作
import matplotlib.pyplot as plt
plt.figure(figsize = (10,10),dpi = 100) #创建指定大小 必须要在开头 不然会为空
img = cv2.imread('path')
plt.imshow(img)
注意:
plt.savefig()要在plt.show()前面
下面三者的区别
cla() # Clear axis
clf() # Clear figure
close() # Close a figure window
plt.cla()
clears an axes, i.e. the currently active axes in the current figure. It leaves the other axes untouched.
plt.clf()
clears the entire current figure with all its axes, but leaves the window opened, such that it may be reused for other plots.
plt.close()
closes a window, which will be the current window, if not specified otherwise.
Which functions suits you best depends thus on your use-case.
The close()
function furthermore allows one to specify which window should be closed. The argument can either be a number or name given to a window when it was created using figure(number_or_name)
or it can be a figure instance fig
obtained, i.e., usingfig = figure()
. If no argument is given to close()
, the currently active window will be closed. Furthermore, there is the syntax close('all')
, which closes all figures.
methods of the Figure class
Additionally, the Figure
class provides methods for clearing figures. I'll assume in the following that fig
is an instance of a Figure
:
fig.clf()
clears the entire figure. This call is equivalent to plt.clf()
only if fig
is the current figure.
fig.clear()
is a synonym for fig.clf()
Note that even del fig
will not close the associated figure window. As far as I know the only way to close a figure window is using plt.close(fig)
as described above