-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plotting functions with more general arrays #78
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,17 @@ export @P_str | |
|
||
const clims_types = (:contour, :contourf, :heatmap, :surface) | ||
|
||
const UMQ = Union{Missing, <:Quantity} | ||
const AVec = AbstractVector | ||
const AArr = AbstractArray | ||
const AArrArrQ = AArr{<:AArr{<:UMQ}} | ||
const AMat{T} = AArr{T,2} where T | ||
|
||
#========== | ||
Main recipe | ||
==========# | ||
|
||
@recipe function f(::Type{T}, x::T) where T <: AbstractArray{<:Union{Missing,<:Quantity}} | ||
@recipe function f(::Type{T}, x::T) where T <: AArr{<:UMQ} | ||
axisletter = plotattributes[:letter] # x, y, or z | ||
if (axisletter == :z) && | ||
get(plotattributes, :seriestype, :nothing) ∈ clims_types | ||
|
@@ -59,8 +65,6 @@ function fixaxis!(attr, x, axisletter) | |
end | ||
|
||
# Recipe for (x::AVec, y::AVec, z::Surface) types | ||
const AVec = AbstractVector | ||
const AMat{T} = AbstractArray{T,2} where T | ||
@recipe function f(x::AVec, y::AVec, z::AMat{T}) where T <: Quantity | ||
u = get(plotattributes, :zunit, unit(eltype(z))) | ||
ustripattribute!(plotattributes, :clims, u) | ||
|
@@ -70,7 +74,7 @@ const AMat{T} = AbstractArray{T,2} where T | |
end | ||
|
||
# Recipe for vectors of vectors | ||
@recipe function f(::Type{T}, x::T) where T <: AbstractVector{<:AbstractVector{<:Union{Missing,<:Quantity}}} | ||
@recipe function f(::Type{T}, x::T) where T <: AVec{<:AVec{<:UMQ}} | ||
axisletter = plotattributes[:letter] # x, y, or z | ||
[fixaxis!(plotattributes, x, axisletter) for x in x] | ||
end | ||
|
@@ -82,19 +86,19 @@ end | |
end | ||
|
||
# Recipes for functions | ||
@recipe function f(f::Function, x::T) where T <: AVec{<:Union{Missing,<:Quantity}} | ||
@recipe function f(f::Function, x::T) where T <: AArr{<:UMQ} | ||
x, f.(x) | ||
end | ||
@recipe function f(x::T, f::Function) where T <: AVec{<:Union{Missing,<:Quantity}} | ||
@recipe function f(x::T, f::Function) where T <: AArr{<:UMQ} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meaningful change |
||
x, f.(x) | ||
end | ||
@recipe function f(x::T, y::AVec, f::Function) where T <: AVec{<:Union{Missing,<:Quantity}} | ||
@recipe function f(x::T, y::AVec, f::Function) where T <: AVec{<:UMQ} | ||
x, y, f.(x',y) | ||
end | ||
@recipe function f(x::AVec, y::T, f::Function) where T <: AVec{<:Union{Missing,<:Quantity}} | ||
@recipe function f(x::AVec, y::T, f::Function) where T <: AVec{<:UMQ} | ||
x, y, f.(x',y) | ||
end | ||
@recipe function f(x::T1, y::T2, f::Function) where {T1<:AVec{<:Union{Missing,<:Quantity}}, T2<:AVec{<:Union{Missing,<:Quantity}}} | ||
@recipe function f(x::T1, y::T2, f::Function) where {T1<:AVec{<:UMQ}, T2<:AVec{<:UMQ}} | ||
x, y, f.(x',y) | ||
end | ||
@recipe function f(f::Function, u::Units) | ||
|
@@ -103,6 +107,25 @@ end | |
(_, xmin, xmax) = recipedata[1].args | ||
return f, xmin*u, xmax*u | ||
end | ||
@recipe function f(u::Units, f::Function) | ||
return f, u | ||
end | ||
Comment on lines
+110
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mirror of |
||
#========================================================================= | ||
If x is an array of arrays of quantities, consider those different series. | ||
No need to dive deeper than this, a plot of arrays of arrays of arrays is | ||
not implemented in Plots. | ||
=========================================================================# | ||
@recipe function f(f::Function, x::AArrArrQ) | ||
for s in x | ||
@series begin | ||
xunit := unit(first(first(x))) | ||
f, s | ||
end | ||
end | ||
end | ||
@recipe function f(x::AArrArrQ, f::Function) | ||
return f, x | ||
end | ||
Comment on lines
+113
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array of array |
||
|
||
""" | ||
```julia | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaningful change