add transformation option

This commit is contained in:
ChrisRackauckas 2017-04-16 13:01:51 -07:00
parent 9a59df793d
commit 7def4e8e73

View File

@ -812,14 +812,30 @@ end
# Splits a complex matrix to its real and complex parts
# Reals defaults solid, imaginary defaults dashed
# Label defaults are changed to match the real-imaginary reference / indexing
@recipe function f{T<:Real,T2<:Number}(x::AbstractArray{T},y::Array{Complex{T2}})
A = real.(y)
B = imag.(y)
_y = [!iseven(i) ? A[:,i÷2+1] : B[:,i÷2] for i in 1:2size(A,2)]
linestyle --> reshape([!iseven(i) ? :solid : :dash for i in 1:2size(A,2)],1,2size(A,2))
label --> reshape([!iseven(i) ? "Re(y$(i÷2+1))" : "Im(y$(i÷2))" for i in 1:2size(A,2)],1,2size(A,2))
color --> reshape([!iseven(i) ? i÷2+1 : i÷2 for i in 1:2size(A,2)],1,2size(A,2))
x,_y
@recipe function f{T<:Real,T2<:Number}(x::AbstractArray{T},y::Array{Complex{T2}};
transformation=:split2D)
if transformation==:split2D
A = real.(y)
B = imag.(y)
_y = [!iseven(i) ? A[:,i÷2+1] : B[:,i÷2] for i in 1:2size(A,2)]
linestyle --> reshape([!iseven(i) ? :solid : :dash for i in 1:2size(A,2)],1,2size(A,2))
label --> reshape([!iseven(i) ? "Re(y$(i÷2+1))" : "Im(y$(i÷2))" for i in 1:2size(A,2)],1,2size(A,2))
color --> reshape([!iseven(i) ? i÷2+1 : i÷2 for i in 1:2size(A,2)],1,2size(A,2))
retval = (x,_y)
elseif transformation==:split3D
A = real.(y)
B = imag.(y)
ylabel --> "Re(y)"
zlabel --> "Im(y)"
retval = (x,A,B)
elseif transformation==:modulus
_y = norm.(y)
label --> reshape(["||y$(i)||" for i in 1:size(_y,2)],1,size(_y,2))
retval = (x,_y)
else
error("Transformation unknown. Please use :split2D, :split3D, or :modulus")
end
(retval...)
end