我有一段代码是从工作中的合作者那里获得的。这段代码生成如下图所示的图。 绘图的示例图像
它通过引用另一段代码中的另一个函数来实现这一点;我不想以任何方式改变这一点。
我想做的是编写一段代码,将该图保存为 png 文件,即我正在寻找一个函数,我可以将另一个函数作为变量,将其保存为 png/jpeg 文件。
代码:
这是代码:
for file in files:
import matplotlib.pyplot as plt
connection = sqlite3.connect( file )
animalPool = AnimalPool( )
animalPool.loadAnimals( connection )
# show the mask of animals at frame 300
animalPool.showMask( 701 )
Run Code Online (Sandbox Code Playgroud)
它正在调用以下函数:
def showMask(self, t ):
'''
show the mask of all animals in a figure
'''
fig, ax = plt.subplots()
ax.set_xlim(90, 420)
ax.set_ylim(-370, -40)
for animal in self.getAnimalList():
mask = animal.getBinaryDetectionMask( t )
mask.showMask( ax=ax )
plt.show()
Run Code Online (Sandbox Code Playgroud)
我已经尝试过 …