Skip to content

Commit 9bb6aeb

Browse files
authored
Merge pull request #156 from pvermees/beta
Scales y-axis of ratio plot to signal window
2 parents 861ad3c + 3063678 commit 9bb6aeb

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/plots.jl

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function plot(samp::Sample;
151151
legend=:topleft,
152152
show_title=true,
153153
titlefontsize=10,
154+
padding::Number=0.1,
154155
kw...)
155156
x, y, ty, xlab, ylab, ylim = prep_plot(samp,channels,num,den,ylim,transformation)
156157
p = Plots.plot(x,Matrix(ty);
@@ -167,18 +168,21 @@ function plot(samp::Sample;
167168
end
168169
Plots.title!(title;titlefontsize=titlefontsize)
169170
end
170-
dy_ax = collect(Plots.ylims(p))
171+
if ylim == :auto
172+
dy_win = collect(Plots.ylims(p))
173+
else
174+
buffer = (ylim[2]-ylim[1])*padding/2
175+
dy_win = (ylim[1] + buffer, ylim[2] - buffer)
176+
end
171177
# plot t0:
172-
Plots.plot!(p,[samp.t0,samp.t0],collect(dy_ax[[1,2]]);
178+
Plots.plot!(p,[samp.t0,samp.t0],collect(dy_win[[1,2]]);
173179
linecolor="grey",linestyle=:dot,label="")
174180
# plot selection windows:
175-
dy_dat = [minimum(Matrix(ty)),maximum(Matrix(ty))]
176-
dy = @. (dy_ax + dy_dat)/2
177181
for win in [samp.bwin,samp.swin]
178182
for w in win
179183
from = x[w[1]]
180184
to = x[w[2]]
181-
Plots.plot!(p,[from,from,to,to,from],collect(dy[[1,2,2,1,1]]);
185+
Plots.plot!(p,[from,from,to,to,from],collect(dy_win[[1,2,2,1,1]]);
182186
linecolor="black",linestyle=:dot,label="")
183187
end
184188
end
@@ -191,12 +195,13 @@ function prep_plot(samp::Sample,
191195
num::Union{Nothing,AbstractString}=nothing,
192196
den::Union{Nothing,AbstractString}=nothing,
193197
ylim=:auto,
194-
transformation::Union{Nothing,AbstractString}=nothing)
198+
transformation::Union{Nothing,AbstractString}=nothing;
199+
padding::Number=0.1)
195200
xlab = names(samp.dat)[1]
196201
x = samp.dat[:,xlab]
197202
meas = samp.dat[:,channels]
198203
ratsig = isnothing(den) ? "signal" : "ratio"
199-
y = (ratsig == "signal") ? meas : formRatios(meas,num,den)
204+
y = (ratsig == "signal") ? meas : formRatios(meas,num,den)
200205
arg = nothing
201206
min_val = minimum(Matrix(y))
202207
if isnothing(transformation)
@@ -209,14 +214,27 @@ function prep_plot(samp::Sample,
209214
end
210215
ty = transformeer(y,transformation)
211216
if ylim == :auto && ratsig == "ratio"
212-
miny = minimum(Matrix(ty))
213-
maxy = maximum(Matrix(ty[x .> samp.t0,:]))
214-
buffer = (maxy-miny)/20
215-
ylim = (miny-buffer,maxy+buffer)
217+
ylim = get_ylim(samp,channels,num,den,transformation;
218+
padding=padding)
216219
end
217220
return x, y, ty, xlab, ylab, ylim
218221
end
219222
export prep_plot
223+
function get_ylim(samp::Sample,
224+
channels::AbstractVector,
225+
num::Union{Nothing,AbstractString}=nothing,
226+
den::Union{Nothing,AbstractString}=nothing,
227+
transformation::Union{Nothing,AbstractString}=nothing;
228+
padding::Number=0.1)
229+
dat = windowData(samp,blank=false,signal=true)
230+
meas = dat[:,channels]
231+
ratsig = isnothing(den) ? "signal" : "ratio"
232+
y = (ratsig == "signal") ? meas : formRatios(meas,num,den)
233+
ty = transformeer(y,transformation)
234+
miny, maxy = extrema(Matrix(ty))
235+
buffer = (maxy-miny)*padding
236+
return (miny-buffer,maxy+buffer)
237+
end
220238

221239
# minerals
222240
function plotFitted!(p,

test/emacs.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ end
88

99
rerun = true
1010

11-
option = "runtests"
12-
# "Camila" # "KJgui" # "Cuba" # "Raman"
11+
option = "Cuba"
12+
# "Camila" # "KJgui" # "runtests" # "Raman"
1313
# "NHM" # "NHM-carbonate" # "Abdulkadir"
1414

1515
if option != "runtests"
@@ -37,8 +37,7 @@ if option == "Raman"
3737

3838
elseif option == "Cuba"
3939

40-
myrun = load("/home/pvermees/Documents/Plasmatrace/" *
41-
"Cuba/YAMIRKA_Ap_32U5Hz_JetH_GEon_3.0J-10A41/";
40+
myrun = load("/home/pvermees/Dropbox/Plasmatrace/Cuba/10A41/";
4241
instrument="FIN2",head2name=false)
4342

4443
method = "U-Pb"

0 commit comments

Comments
 (0)