Plot 如何在具有透明度的Julia中覆盖打印(使用打印)
我正在解决一个问题。它需要将一个图与另一个图重叠。描述了使用plots软件包覆盖绘图的方法,但名称中带有Plot 如何在具有透明度的Julia中覆盖打印(使用打印),plot,julia,Plot,Julia,我正在解决一个问题。它需要将一个图与另一个图重叠。描述了使用plots软件包覆盖绘图的方法,但名称中带有alpha的任何一个都不会增加绘图的透明度(代码如下) 如何使用Plots软件包向julia v1.0.0中的填充等高线图添加透明度 import Plots struct Sectors{T} values::Vector{T} n::Int Sectors(values::Vector{T}) where T = new{T}(values, length(val
alpha
的任何一个都不会增加绘图的透明度(代码如下)
如何使用Plots软件包向julia v1.0.0中的填充等高线图添加透明度
import Plots
struct Sectors{T}
values::Vector{T}
n::Int
Sectors(values::Vector{T}) where T = new{T}(values, length(values))
end
mutable struct Radius{T}
value::T
radius::Union{T, Nothing}
next::Union{Radius{T}, Nothing}
sectors::Union{Sectors{T}, Nothing}
function Radius(radius::T,
value::T;
next::Union{Radius{T}, Nothing} = nothing,
sectors::Union{Sectors{T}, Nothing}=nothing) where T
new{T}(value, radius, nothing, nothing)
end
end
function create(radiuses::Vector{T},
radius_vals::Vector{T},
sector_vals::Vector{Union{Nothing, Vector{T}}})::Radius{T} where T
r = Radius(radiuses[1], radius_vals[1])
if sector_vals[1] !== nothing
r.sectors = Sectors(sector_vals[1])
end
k = r
for i in 2:length(radiuses)
n = Radius(radiuses[i], radius_vals[i])
k.next = n
k = n
if sector_vals[i] !== nothing
n.sectors = Sectors(sector_vals[i])
end
end
r
end
function filter(r::T, α::T, rads::Radius{T})::T where T<:Number
while true
if (abs(r) <= rads.radius)
if (rads.sectors !== nothing)
return rads.sectors.values[convert(Int,
fld(α + π/2 + π/rads.sectors.n/2,
π/(rads.sectors.n-1)) + 1)]
else
return rads.value
end
else
if (rads.next !== nothing)
rads = rads.next
else
return 0
end
end
end
end
function construct_board(xy::AbstractMatrix{T})::AbstractMatrix{T} where T<:Number
rads = create(T[14.2, 31.8, 184.1 , 203.2, 304.8, 323.8, 425.5],
T[1, 0, 1, 0, 1, 0, 1],
[nothing,
nothing,
T[0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3],
T[0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7],
T[0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3],
T[0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7],
nothing])
target = zeros(size(xy, 1), size(xy, 1))
for i in eachindex(xy[:, 1])
for j in eachindex(xy[:, 2])
x = xy[i, 1]
y = xy[j, 2]
α = atan(y/x)
r = sqrt(x^2 + y^2)
target[i, j] = filter(r, α, rads)
end
end
target
end
function filter2(x::T, y::T, σx::T, σy::T)::T where T<:Number
return 1/(2π*σx*σy)*exp(-x^2/2σx^2-y^2/2σy^2)
end
function construct_hits(xy::AbstractMatrix{T})::AbstractMatrix{T} where T<:Number
target = zeros(size(xy, 1), size(xy, 1))
for i in eachindex(xy[:, 1])
for j in eachindex(xy[:, 2])
x = xy[i, 1]
y = xy[j, 2]
σx = 54.
σy = 90.
target[i, j] = filter2(x, y, σx, σy)
end
end
m, i = findmax(target)
target ./ m
end
function main()
Plots.plotly() # same results with gr backend
a = construct_board(cat(-500.:1:500, -500.:1:500, dims=2))
plot_a = Plots.contourf(a)
b = construct_hits(cat(-500.:1:500, -500.:1:500, dims=2))
plot_b = Plots.contourf!(b,
seriesalpha = 0.1 )
p = Plots.plot(plot_a, plot_b)
display(p)
end
main()
导入绘图
结构扇区{T}
值::向量{T}
n::Int
扇区(值::向量{T}),其中T=new{T}(值,长度(值))
结束
可变结构半径{T}
值::T
半径::并集{T,Nothing}
next::并集{Radius{T},Nothing}
扇区::联合{sections{T},Nothing}
函数半径(半径::T,
值::T;
next::并集{Radius{T},Nothing}=Nothing,
扇区::联合{sections{T},Nothing}=Nothing),其中T
新{T}(值、半径、无、无)
结束
结束
函数create(radius::Vector{T},
半径:向量{T},
扇区:向量{Union{Nothing,向量{T}}}):半径{T},其中T
r=半径(半径[1],半径[1])
如果扇区值[1]!==没有什么
r、 扇区=扇区(扇区值[1])
结束
k=r
对于2中的i:长度(半径)
n=半径(半径[i],半径[i])
k、 下一个=n
k=n
如果扇区值[i]!==没有什么
n、 扇区=扇区(扇区值[i])
结束
结束
R
结束
函数过滤器(r::T,α::T,rads::Radius{T})::T其中T结果是,seriesalpha
是我需要的设置。但是,当使用gr
后端时,它不起作用。您能在这里提供一个MWE吗?到目前为止提供的代码有未定义的引用。@rickhg12hs添加了完整的代码