首页 > 解决方案 > 朱莉娅:marker_z 需要很多时间

问题描述

我正在尝试进行渐变绘图。

using Plots
using LinearAlgebra

L = 60 #size of a matrix
N = 10000 #number of loops

E = zeros(Complex{Float64},N,L) #set of eigenvalues
IPR = zeros(Complex{Float64},N,L) #indicator for marker_z

准备电子和知识产权

function main() 

cnt = 0 
    
for i = 1:N
    cnt += 1
    H = rand(Complex{Float64},L,L) 
    eigenvalue,eigenvector = eigen(H)
    
        for j = 1:L
            E[cnt,j] = eigenvalue[j] 
            IPR[cnt,j] = abs2(norm(abs2.(eigenvector[:,j])))/(abs2(norm(eigenvector[:,j])))
        end

end

end

绘图

function main1()

plot(real.(E),imag.(E),marker_z = real.(IPR),st = scatter,markercolors=:cool,markerstrokewidth=0,markersize=1,dpi=300) 
plot!(legend=false,xlabel="ReE",ylabel="ImE") 
savefig("test.png")
    
end

@time main1()

358.794885 seconds (94.30 M allocations: 129.882 GiB, 2.05% gc time)

与均匀绘图相比,渐变绘图需要太多时间。

function main2()

plot(real.(E),imag.(E),st = scatter,markercolor=:blue,markerstrokewidth=0,markersize=1,dpi=300) 
plot!(legend=false,xlabel="ReE",ylabel="ImE") 
savefig("test1.png")
    
end

@time main2()

8.100609 seconds (10.85 M allocations: 508.054 MiB, 0.47% gc time)

有没有一种像均匀绘图一样快的渐变绘图方法?

标签: plotjuliavisualization

解决方案


我自己解决了这个问题。
从 Julia 1.3.1 更新到 Julia1.6.3 后,我检查了 main1 随着比尔的评论变得更快。


推荐阅读