Skip to content

Commit 1bd8335

Browse files
authored
Fix plotticks for consequtive plots (#189)
1 parent 981c859 commit 1bd8335

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/plotting.jl

+23-5
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,38 @@ default to extrema(wmag) if xlims/ylims not defined or empty
4444
"""
4545
function getlims(xylims, plotattributes, wmag)
4646
lims = get(plotattributes, xylims, extrema(wmag))
47-
if lims isa Tuple{<:Number, <:Number} # If x/ylims not supplied as empty
48-
return lims
49-
else
50-
return extrema(wmag)
47+
if !isa(lims, Tuple{<:Number, <:Number}) # If x/ylims not supplied as empty
48+
lims = extrema(wmag)
49+
end
50+
if !isempty(get_serieslist(plotattributes))
51+
subplot = get(plotattributes, :subplot, 0)
52+
subplot == 0 && (return lims)
53+
se = seriesextrema(xylims, plotattributes, subplot)
54+
lims = extremareducer(lims, se)
55+
end
56+
lims
57+
end
58+
59+
get_serieslist(plotattributes) = plotattributes[:plot_object].series_list
60+
get_serieslist(plotattributes, subplot) = plotattributes[:plot_object].subplots[subplot].series_list
61+
62+
function seriesextrema(xylims, plotattributes, subplot)
63+
serieslist = get_serieslist(plotattributes, subplot)
64+
isempty(serieslist) && (return (Inf, -Inf))
65+
sym = xylims == :xlims ? :x : :y
66+
mapreduce(extremareducer, serieslist) do series
67+
extrema(series[sym])
5168
end
5269
end
70+
extremareducer(x,y) = (min(x[1],y[1]),max(x[2],y[2]))
5371

5472
function getLogTicks(x, minmax)
5573
minx, maxx = minmax
5674
major_minor_limit = 6
5775
minor_text_limit = 8
5876
min = ceil(log10(minx))
5977
max = floor(log10(maxx))
60-
major = 10 .^ collect(min:max)
78+
major = 10 .^ (min:max)
6179
if Plots.backend() != Plots.GRBackend()
6280
majorText = [latexstring("\$10^{$(round(Int64,i))}\$") for i = min:max]
6381
else

0 commit comments

Comments
 (0)