Skip to content

Commit cf672f7

Browse files
authored
Merge pull request #121 from jbisits/distributionfixes
Fixes for distribution plotting
2 parents 2bb2178 + de4d532 commit cf672f7

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

ext/TLDNSMakieExt/plotrecipes.jl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function TLDNS.animate_2D_field(field_timeseries::FieldTimeSeries, field_name::A
6565
end
6666
function TLDNS.animate_2D_field(rs::Raster, xslice::Int64, yslice::Int64; colormap = :thermal,
6767
colorrange = nothing, highclip = nothing, lowclip = nothing,
68-
aspect_ratio = 1, profile_xlims = nothing)
68+
aspect_ratio = 1, vline = nothing)
6969

7070
x, z, t = lookup(rs, :xC), lookup(rs, :zC), lookup(rs, :Ti)
7171
field_name = string(rs.name)
@@ -94,8 +94,11 @@ function TLDNS.animate_2D_field(rs::Raster, xslice::Int64, yslice::Int64; colorm
9494
ax[2].ylabel = "z"
9595
ax[2].aspect = aspect_ratio
9696
ax[2].xaxisposition = :top
97-
if !isnothing(profile_xlims)
98-
xlims!(ax[2], profile_xlims)
97+
ax[2].xticklabelrotation = π / 4
98+
if !isnothing(vline)
99+
vlines!(ax[2], vline, linestyle = :dash, color = :red,
100+
label = "Predicted maximum density")
101+
axislegend(ax[2])
99102
end
100103

101104
linkyaxes!(ax[1], ax[2])
@@ -114,23 +117,35 @@ end
114117
"""
115118
function animate_volume_distributions(rs::Raster)
116119
Animate the volume distribution from each saved snapshot of data for the variable saved as
117-
a `Raster`.
120+
a `Raster`. Optional arguments:
121+
- `edges` for the bins, in `nothing` the edges for the first fitted `Histogram` are used for
122+
the subsequent histograms;
123+
- `unit` for the variable that is being plotted - must be a `String`.
118124
"""
119-
function TLDNS.animate_volume_distributions(rs::Raster, edges::AbstractVector; unit = nothing)
120-
121-
rs_series = slice(rs, Ti)
122-
t = lookup(rs_series, Ti)
123-
rs_series_hist = RasterLayerHistogram.(rs_series, edges)
125+
function TLDNS.animate_volume_distributions(rs::Raster; edges = nothing, unit = nothing)
126+
127+
t = lookup(rs, Ti)
128+
rs_series_hist = Vector{RasterLayerHistogram}(undef, length(t))
129+
for i eachindex(t)
130+
if i == 1
131+
rs_series_hist[i] = isnothing(edges) ? RasterLayerHistogram(rs[:, :, :, i]) :
132+
RasterLayerHistogram(rs[:, :, :, i], edges)
133+
else
134+
rs_series_hist[i] = RasterLayerHistogram(rs[:, :, :, i],
135+
rs_series_hist[1].histogram.edges[1])
136+
end
137+
end
124138
n = Observable(1)
125-
@lift rs_series_hist[$n]
139+
dₜ = @lift rs_series_hist[$n]
126140
time_title = @lift @sprintf("t=%1.2f minutes", t[$n] / 60)
127141

128142
fig = Figure(size = (500, 500))
129143
xlabel = isnothing(unit) ? string(rs.name) : string(rs.name) * unit
144+
xlimits = isnothing(edges) ? rs_series_hist[1].histogram.edges[1] : edges
130145
ylabel = "Volume (m³)"
131146
ax = Axis(fig[1, 1], title = time_title; xlabel, ylabel)
132-
133-
plot!(ax, rs_series_hist[1], color = :steelblue)
147+
xlims!(ax, xlimits[1], xlimits[end])
148+
plot!(ax, dₜ, color = :steelblue)
134149

135150
frames = eachindex(t)
136151
record(fig, joinpath(pwd(), string(rs.name) * "_vd.mp4"), frames, framerate=8) do i

0 commit comments

Comments
 (0)