如何使用 Plots() 在 Julia 中绘制背景图像

How to plot on a background image in Julia using Plots()

我正在尝试将基本图叠加到图像上。根据 Julia Docs 还不清楚:http://docs.juliaplots.org/latest/examples/pyplot/

如何在图像上绘图?这是我在 Julia 中的代码:

using Plots

x_coordinate_holder = [30515.4, 30515.4, 30490.9, 30470.7, 30470.7, 30450.9, 30450.0,
30450.0, 30450.0, 30450.0, 30450.0, 30430.8, 30449.2, 30469.4,
30469.4, 30469.4, 30489.2, 30489.2, 30489.2, 30509.4, 30529.1,
30549.4, 30569.2, 30589.3, 30590.0, 30609.2, 30610.0, 30610.0,
30590.7, 30590.7, 30590.7, 30570.8, 30570.0, 30570.0, 30589.4,
30589.4, 30589.4, 30590.0, 30570.6, 30550.8, 30569.2, 30569.2,
30589.4, 30589.4, 30570.6, 30570.6, 30570.6, 30570.6, 30550.8,
30530.6, 30510.8, 30510.0, 30510.0, 30529.3, 30549.1, 30549.1,
30569.3, 30570.0, 30589.3, 30590.0, 30590.0, 30590.0, 30609.3,
30610.0, 30610.0, 30610.0, 30629.2, 30649.4, 30669.2, 30689.4,
30709.2, 30710.0, 30710.0]
y_coordinate_holder = [14186.3, 14186.3, 14209.2, 14229.3, 14229.3, 14249.1, 14269.3,
14269.3, 14269.3, 14269.3, 14269.3, 14289.1, 14290.0, 14290.0,
14290.0, 14290.0, 14309.2, 14309.2, 14309.2, 14329.4, 14330.0,
14349.4, 14369.2, 14389.3, 14370.5, 14350.8, 14330.6, 14330.6,
14330.0, 14330.0, 14330.0, 14349.2, 14330.8, 14330.8, 14310.6,
14310.6, 14310.6, 14290.8, 14270.6, 14270.0, 14270.0, 14270.0,
14270.0, 14270.0, 14270.0, 14270.0, 14270.0, 14270.0, 14270.0,
14250.6, 14250.0, 14230.7, 14249.1, 14230.7, 14210.9, 14210.9,
14190.7, 14209.1, 14190.7, 14209.5, 14209.5, 14209.5, 14210.0,
14229.3, 14210.9, 14190.7, 14209.2, 14210.0, 14190.8, 14190.0,
14190.0, 14209.3, 14209.3]

plotly()
plot(x_coordinate_holder, y_coordinate_holder, color = :blue, linewidth=2)
gui() 

注:我看了

此示例不再有效,这就是我再次提出问题的原因。这是我更新的代码。

plotly()
img = Image("/path/to/image/file/exmaple/test.png)

plot(img)
plot!(x_coordinate_holder, y_coordinate_holder, color = :blue, linewidth=2)
gui() #Should open up a browser window/tab and show the plot in there.

当 运行 出现以下错误时:

* **ERROR: LoadError: UndefVarError: Image not defined** *

谁能提供一个完整的例子?

下面是绘制带有绘图的图像并自动缩放的代码:

using Plots 
using Images
img = load("/Users/xxxx/xxxx/xxxx-xxxx.png")

xMin = minimum(x_coordinate_holder)-30
xMax = maximum(x_coordinate_holder)+30
yMin = minimum(y_coordinate_holder)-30
yMax = maximum(y_coordinate_holder)+30

#print("X-Coords: ", xMin, ", ", xMax, " Y-Coords: ", yMin, ", ", yMax, "\n")

plot1 = plot(img, xlim=(xMin,xMax), ylim=(yMin, yMax), yflip = false)
plot1 = plot!(x_coordinate_holder, y_coordinate_holder, color = :black, linewidth=0.4)
plot2 = plot(e_holder, color = :orange, linewidth=2)
plot(plot1, plot2)
gui()

请注意,xlim 和 ylim 允许我绘制的图像与绘图的大小成比例缩放(即,如果绘图较大,它会自动缩放图像以显示完整的绘图)。

请注意,x_coordinate_holder、y_coordinate_holder 和 e_holder 只是我在 运行 这段代码之前定义的数组。

此代码使 plot1 和 plot2 并排显示。

另外值得一提的是,我尝试使用 plotly 来做到这一点,但没有成功。我让它在没有适当的图像缩放的情况下工作,但是当我尝试缩放图像时它不再起作用所以我去了默认后端。