我做了一个群组模拟,我试图在给定的时间得到一个简单的表示,比如:new to the site so here is the link。我使用Spyder,当我使用plt.show()在ipython中显示图像时,代码工作得非常出色,但是当我尝试使用plt.savefig()保存图像时(在此之前我删除了plt.show(),而不是问题),我最终得到了空白图像。代码如下:
p,v,t = resolve() #p[c][i] is the position vector of individual i at time t[c]
N = len(t) # number of instant
n = len(m) # number of individual
murs_x = [w[0] for w in W] # wall points x coordinates
murs_y = [w[1] for w in W] # wall points y coordinates
conv = 39.3701 #inch/m
L = longueur*conv/50 # width of figure
H = (largeur + decalage)*conv/50 # height of figure
for c in range(N):
fig1 = plt.figure(num="aff",figsize = (L,H), dpi = 200) # arbitrary num, allow to recreate the figure
ax = fig1.add_axes([1,1,1,1])
ax.set_axis_off() # visual purpose
ax.set_frame_on(False) # visual purpose
ax.axis([0,longueur,0,largeur+decalage])
ax.scatter(murs_x,murs_y,s=0.01,marker='.')
for i in range(n):
if p[c][i][1] <= (largeur + r[i]): # presence condition for individual i
ax.add_artist(plt.Circle((p[c][i][0], p[c][i][1]), r[i], alpha=1))
# drawing of the circle representing individual i
# here is the plt.show(), unused
fig1.savefig(str(c)+".png") # trying to save instant c visual represention
fig1.clf()
此外,如果没有用于视觉目的的2行,图像不是完全空白的,而是这样:another link。 我第一次尝试使用matplotlib.animation创建视频,但是我遇到了相同的问题,即在右上角有两个裁剪过的零的空白视频。我认为这个问题与艺术家课程有关(我使用分散的点而不是圆来代表每个人的效果更好),但我是一个初学者,不知道如何精确地处理它。至少图像的大小是预期的大小
谢谢你阅读这篇文章
目前没有回答
相关问题 更多 >
编程相关推荐