Skip to content

Commit

Permalink
fix plotting of set vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 27, 2023
1 parent 8ea0bd2 commit 582d090
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/Plotting/plot_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ function _extract_limits(p::RecipesBase.AbstractPlot,
lims[:x] = :auto
lims[:y] = :auto
end
lims[:x_explicit] = RecipesBase.is_explicit(plotattributes, :xlims)
lims[:y_explicit] = RecipesBase.is_explicit(plotattributes, :ylims)

# check whether the current call to `plot`/`plot!` passed new bounds
if haskey(plotattributes, :xlims)
Expand Down Expand Up @@ -57,26 +55,20 @@ function _update_plot_limits!(lims, X::LazySet)

box_min = low(box)
box_max = high(box)
for (idx, symbols) in enumerate(((:x, :x_explicit), (:y, :y_explicit)))
symbol, symbol_explicit = symbols
if lims[symbol] != :auto || !lims[symbol_explicit]
if lims[symbol] == :auto
Δmax = box_max[idx]
Δmin = box_min[idx]
else
# width of the plotting window including the new set in the `symbol` direction
Δmax = max(lims[symbol][2], box_max[idx])
Δmin = min(lims[symbol][1], box_min[idx])
end
width = Δmax - Δmin
for (idx, symbol) in enumerate((:x, :y))
if lims[symbol] != :auto
# width of the plotting window including the new set in the `symbol` direction
dmin = min(lims[symbol][1], box_min[idx])
dmax = max(lims[symbol][2], box_max[idx])
width = dmax - dmin

# scaling factor for beautification
ϵ = 0.05
ϵ = 0.03
offset = width * ϵ

# extend the current plot limits if the new set (plus a small offset) falls outside
lims[symbol] = (min(Δmin, box_min[idx] - offset),
max(Δmax, box_max[idx] + offset))
lims[symbol] = (min(lims[symbol][1], box_min[idx] - offset),
max(lims[symbol][2], box_max[idx] + offset))
end
end
return nothing
Expand Down Expand Up @@ -534,8 +526,8 @@ end
extr = _extract_extrema(p)
if isbounded(cup)
B = box_approximation(cup)
extr[:x] = (max(extr[:x][1], low(B, 1)), min(extr[:x][2], high(B, 1)))
extr[:y] = (max(extr[:y][1], low(B, 2)), min(extr[:y][2], high(B, 2)))
extr[:x] = (min(extr[:x][1], low(B, 1)), max(extr[:x][2], high(B, 1)))
extr[:y] = (min(extr[:y][1], low(B, 2)), max(extr[:y][2], high(B, 2)))
end
# if there is already a plotted set and the limits are fixed,
# automatically adjust the axis limits (e.g. after plotting an
Expand Down

0 comments on commit 582d090

Please sign in to comment.