如何将滑块添加到此绘图函数



我有一个函数,可以创建带有滑块的绘图。该代码基于Makie教程的第一个示例

function plotLaneEmden(log_delta_xi=-4, n=3)    
fig = Figure()
ax = Axis(fig[1, 1])

sl_x = Slider(fig[2, 1], range = 0:0.01:4.99, startvalue = 3)
sl_y = Slider(fig[1, 2], range = -6:0.01:0.1, horizontal = false, startvalue = -2)
point = lift(sl_x.value, sl_y.value) do n, log_delta_xi
Point2f(n, log_delta_xi)
end
plot(n,  1 .- log_delta_xi.^2/6,  linecolor = :green, label="n = $n")

xlabel!("ξ")
ylabel!("θ")
end

我收到错误和警告信息:

WARNING: both GLMakie and Plots export "ylabel!"; uses of it in module Main must be qualified
WARNING: both GLMakie and Plots export "xlabel!"; uses of it in module Main must be qualified
WARNING: both GLMakie and Plots export "plot"; uses of it in module Main must be qualified
UndefVarError: plot not defined

我在这里错过了什么?

您的代码中有:

using GLMakie 
using Plots 

这将导致两个模块都导出plot命令。在这种情况下,你需要写:

GLMakie.plot(....)
GLMakie.xlabel!("ξ")

你也可以考虑做:

using GLMakie 
import Plots 

在这种情况下,两个库的命名不会发生冲突。您仍然可以通过键入Plots.methodname(.....)来使用Plots中的任何方法

最新更新