Background image with specific coordinates in Plots.jl

How can a background image be added at specific coordinates (and with a specific scale) on a Plots.jl plot?

Assume you have an image of a floor plan whose corner points are associated with specific coordinates, and you’d like to draw additional objects on top.

I can specify the limits of a plot (fitting the domain of the floor plan), and I can draw additional geometries.

using Plots
using FileIO

bg_img = load("floorplan.jpg")

p = plot(bg_img, xlim=(-1,2), ylim=(-3,4))

plot!(p, [-1,2], [-3,4], color="red")

savefig(p, "floorplan_with_geometries.png")                   

How can I instruct Plots.jl to scale the background image as desired (such that its corner points coincide with the axis limits)?

Many thanks in advance.

You could do something like:

sz = size(bg_img)
x, y = LinRange(-1, 2, sz[1]), LinRange(-3, 4, sz[2])
plot(x, y, bg_img)
1 Like