Skip to content

Commit

Permalink
fixed plot(simres) #20
Browse files Browse the repository at this point in the history
  • Loading branch information
arturgower committed Jun 7, 2018
1 parent af1a810 commit 6ba63a6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
65 changes: 32 additions & 33 deletions src/plot/plot.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
include("plot_domain.jl")
# include("plot_moments.jl")

# Plot the result across angular frequency for a specific position (x)
@recipe function plot(simres::SimulationResult;
x = simres.x,
x_indices = [findmin(norm(z - y) for z in simres.x)[2] for y in x],
ω_indices = Colon())

for x_ind in x_indices

complex_field = field(simres)[x_ind, ω_indices]

@series begin
label --> "Real x=$(simres.x[x_ind])"
(transpose(getfield(simres, 3)[ω_indices]), real.(complex_field))
end

@series begin
label --> "Imag x=$(simres.x[x_ind])"
(transpose(getfield(simres, 3)[ω_indices]), imag.(complex_field))
end
end
end

# Plot the result in space (across all x) for a specific angular frequency
@recipe function plot(simres::SimulationResult, ω::AbstractFloat;
x_indices::Union{UnitRange{Int},Colon,AbstractVector{Int}} = Colon(),
ω_index = findmin(abs.(simres.ω .- ω))[2],
field_apply = real, seriestype=:surface)
@recipe function plot(simres::SimulationResult, ω_or_t::AbstractFloat;
x_indices = indices(simres.x,1),
ω_or_t_index = findmin(abs.(getfield(simres, 3) .- ω_or_t))[2],
field_apply = real, seriestype = :surface)

x = [x[1] for x in simres.x[x_indices]]
y = [x[2] for x in simres.x[x_indices]]
ω_or_t = getfield(simres, 3)[ω_or_t_index]

fillcolor --> :pu_or
title --> "Field at $(fieldnames(simres)[end])=$ω_or_t"
seriestype --> seriestype
aspect_ratio --> 1.0

if seriestype == :contour

Expand All @@ -20,45 +48,16 @@ include("plot_domain.jl")
n_y = length(y)

fill --> true
fillcolor --> :pu_or
title --> "Field at $(fieldnames(simres)[end])=$ωt"
seriestype := :contour
x, y, field_apply.(transpose(reshape(field(simres)[x_indices,ω_index],n_y,n_x)))

else

ω_or_t = getfield(simres, 3)[ω_index]
seriestype := :surface
fillcolor --> :pu_or
title --> "Field at $(fieldnames(simres)[end])=$ω_or_t"
(x, y, field_apply.(field(simres)[x_indices,ω_index]))

end

end

# Plot the result across angular frequency for a specific position (x)
@recipe function plot(simres::SimulationResult;
x::Vector{AbstractVector} = simres.x,
x_indices::AbstractVector{Int} = [findmin(norm(z - y) for z in simres.x)[2] for y in x],
ω_indices::Union{UnitRange{Int},Colon,AbstractVector{Int}}=Colon())

for x_ind in x_indices

complex_field = field(simres)[x_ind, ω_indices]

@series begin
label --> "Real x=$(simres.x[x_ind])"
(transpose(getfield(simres, 3)[ω_indices]), real.(complex_field))
end

@series begin
label --> "Imag x=$(simres.x[x_ind])"
(transpose(getfield(simres, 3)[ω_indices]), imag.(complex_field))
end
end
end

"Plot just the particles"
@recipe function plot(sim::FrequencySimulation; bounds = :auto)

Expand Down
13 changes: 7 additions & 6 deletions test/plot_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ sim = FrequencySimulation(sound_sim, particles, source)

ω = 0.5

using Plots ; pyplot()

plot(sim,ω)
plot!(sim)

bounds = Rectangle([-0.,-1.], [10.,1.])
ωs = 0.:0.1:1.
simres = run(sim, bounds, ωs)
timres = run(sim, bounds, ωs; ts = [30.], result_in_time=true)

using Plots ; pyplot()

plot(sim,ω)
plot!(sim)

plot(simres; x = [[1,1]])
plot(simres,0.3)
plot(simres,0.3, seriestype=:contour)
plot(simres, 0.3, seriestype=:contour)

# include("plot_field.jl")
# plot_field(simres, linetype=:contour)
Expand Down

0 comments on commit 6ba63a6

Please sign in to comment.