Merge pull request #2162 from daschw/any
allow plotting of Any vectors and 3D plots
This commit is contained in:
commit
1db3b69489
@ -726,6 +726,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
|
|
||||||
elseif typeof(z) <: AbstractVector
|
elseif typeof(z) <: AbstractVector
|
||||||
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
|
# tri-surface plot (http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#tri-surface-plots)
|
||||||
|
@show x, y, z
|
||||||
handle = ax."plot_trisurf"(x, y, z;
|
handle = ax."plot_trisurf"(x, y, z;
|
||||||
label = series[:label],
|
label = series[:label],
|
||||||
zorder = series[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
|
|||||||
@ -21,32 +21,44 @@ handlemissings(s::Surface) = Surface(handlemissings(s.surf))
|
|||||||
handlemissings(v::Volume) = Volume(handlemissings(v.v), v.x_extents, v.y_extents, v.z_extents)
|
handlemissings(v::Volume) = Volume(handlemissings(v.v), v.x_extents, v.y_extents, v.z_extents)
|
||||||
|
|
||||||
# default: assume x represents a single series
|
# default: assume x represents a single series
|
||||||
convertToAnyVector(x) = Any[prepareSeriesData(x)]
|
convertToAnyVector(x, plotattributes) = Any[prepareSeriesData(x)]
|
||||||
|
|
||||||
# fixed number of blank series
|
# fixed number of blank series
|
||||||
convertToAnyVector(n::Integer) = Any[zeros(0) for i in 1:n]
|
convertToAnyVector(n::Integer, plotattributes) = Any[zeros(0) for i in 1:n]
|
||||||
|
|
||||||
# vector of data points is a single series
|
# vector of data points is a single series
|
||||||
convertToAnyVector(v::AVec{<:DataPoint}) = Any[prepareSeriesData(v)]
|
convertToAnyVector(v::AVec{<:DataPoint}, plotattributes) = Any[prepareSeriesData(v)]
|
||||||
|
|
||||||
# list of things (maybe other vectors, functions, or something else)
|
# list of things (maybe other vectors, functions, or something else)
|
||||||
convertToAnyVector(v::AVec) = vcat((convertToAnyVector(vi) for vi in v)...)
|
function convertToAnyVector(v::AVec, plotattributes)
|
||||||
|
if all(x -> isa(x, Number) || ismissing(x), v) || all(x -> isa(x, AbstractString) || ismissing(x), v)
|
||||||
|
convertToAnyVector(convert.(DataPoint, v), plotattributes)
|
||||||
|
else
|
||||||
|
vcat((convertToAnyVector(vi, plotattributes) for vi in v)...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Matrix is split into columns
|
# Matrix is split into columns
|
||||||
convertToAnyVector(v::AMat{<:DataPoint}) = Any[prepareSeriesData(v[:,i]) for i in 1:size(v,2)]
|
function convertToAnyVector(v::AMat{<:DataPoint}, plotattributes)
|
||||||
|
if all3D(plotattributes)
|
||||||
|
Any[prepareSeriesData(Surface(v))]
|
||||||
|
else
|
||||||
|
Any[prepareSeriesData(v[:, i]) for i in 1:size(v, 2)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Fillranges & ribbons
|
# Fillranges & ribbons
|
||||||
|
|
||||||
|
|
||||||
process_fillrange(range::Number) = [range]
|
process_fillrange(range::Number, plotattributes) = [range]
|
||||||
process_fillrange(range) = convertToAnyVector(range)
|
process_fillrange(range, plotattributes) = convertToAnyVector(range, plotattributes)
|
||||||
|
|
||||||
process_ribbon(ribbon::Number) = [ribbon]
|
process_ribbon(ribbon::Number, plotattributes) = [ribbon]
|
||||||
process_ribbon(ribbon) = convertToAnyVector(ribbon)
|
process_ribbon(ribbon, plotattributes) = convertToAnyVector(ribbon, plotattributes)
|
||||||
# ribbon as a tuple: (lower_ribbons, upper_ribbons)
|
# ribbon as a tuple: (lower_ribbons, upper_ribbons)
|
||||||
process_ribbon(ribbon::Tuple{Any,Any}) = collect(zip(convertToAnyVector(ribbon[1]),
|
process_ribbon(ribbon::Tuple{Any,Any}) = collect(zip(convertToAnyVector(ribbon[1], plotattributes),
|
||||||
convertToAnyVector(ribbon[2])))
|
convertToAnyVector(ribbon[2], plotattributes)))
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -110,17 +122,17 @@ struct SliceIt end
|
|||||||
z = z.data
|
z = z.data
|
||||||
end
|
end
|
||||||
|
|
||||||
xs = convertToAnyVector(x)
|
xs = convertToAnyVector(x, plotattributes)
|
||||||
ys = convertToAnyVector(y)
|
ys = convertToAnyVector(y, plotattributes)
|
||||||
zs = convertToAnyVector(z)
|
zs = convertToAnyVector(z, plotattributes)
|
||||||
|
|
||||||
|
|
||||||
fr = pop!(plotattributes, :fillrange, nothing)
|
fr = pop!(plotattributes, :fillrange, nothing)
|
||||||
fillranges = process_fillrange(fr)
|
fillranges = process_fillrange(fr, plotattributes)
|
||||||
mf = length(fillranges)
|
mf = length(fillranges)
|
||||||
|
|
||||||
rib = pop!(plotattributes, :ribbon, nothing)
|
rib = pop!(plotattributes, :ribbon, nothing)
|
||||||
ribbons = process_ribbon(rib)
|
ribbons = process_ribbon(rib, plotattributes)
|
||||||
mr = length(ribbons)
|
mr = length(ribbons)
|
||||||
|
|
||||||
# @show zs
|
# @show zs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user