动画速度比分开画每帧慢很多

、、、

``````using SparseArrays
using LightGraphs
using GraphPlot
using Plots
function PlotGraphWithLoc(G::Graph, Loc::Dict, Width::Dict=Dict())
#return x,y,lw that can reproduce the network
ne = LightGraphs.ne(G)
x = Array{Float64,2}(undef,2,ne)
y = Array{Float64,2}(undef,2,ne)
lws = ones(Float64,1,ne)
i = 1
if Width != Dict()
width_max = maximum(values(Width))
for e in edges(G)
u,v = src(e), dst(e)
x[1,i]=Loc[u][1]
x[2,i]=Loc[v][1]
y[1,i]=Loc[u][2]
y[2,i]=Loc[v][2]
lws[1,i] = Width[(u,v)]/width_max*3
i += 1
end
else
for e in edges(G)
u,v = src(e), dst(e)
x[1,i]=Loc[u][1]
x[2,i]=Loc[v][1]
y[1,i]=Loc[u][2]
y[2,i]=Loc[v][2]
i += 1
end
end
(x, y, lws)
end
N_x = 100
N_y = 10
N = N_x*N_y
xs = [fld(i,N_y) for i in 0:N-1]
ys = [rem(i,N_y) for i in 0:N-1]
A = zeros(N,N)
for i in 1:N, j in 1:N
abs(xs[i]-xs[j])+abs(ys[i]-ys[j])== 1 ? A[i,j]=1 : nothing
end
G = Graph(A)
Locs=Dict([(i,[xs[i],ys[i]]) for i in 1:N]);
gr()
plot()
@time x_g,y_g,lws = PlotGraphWithLoc(G,Locs)
@time plot!(x_g,y_g,lw=lws,color=:black,legend=false,lt=:path)
scatter!([Locs[i][1] for i in 1:N_y],[Locs[i][2] for i in 1:N_y], label = nothing)
scatter!([Locs[i][1] for i in N-N_y+1:N],[Locs[i][2] for i in N-N_y+1:N], label = nothing)
``````

``````@time anim = @animate for t in 1:10:100
x,y,lws= PlotGraphWithLoc(G,Locs, I_dict_time[t])
plot(x,y,lw=lws,color=:black,legend=false,grid= false, axis=false)
end
mp4(anim,fps=10)
``````