【问题标题】:How do I delete dots created by scatter! in Julia (using Makie)如何删除分散创建的点!在 Julia 中(使用 Makie)
【发布时间】:2021-12-25 13:40:51
【问题描述】:

我对 Julia 很陌生。我目前正在开发一个小程序,这需要我绘制一个点并稍后将其删除(每次只有一个点)。 我正在使用 Makie 包来可视化所有内容,但我还没有找到删除点的方法,该点是由 scatter(或 scatter!)绘制的。 代码应如下所示:

scene = scatter([0],[0], color="blue", markersize=10)
pop!(scene.scatter) #command that removes the dot drawn by the above scatter

我发现了这个线程 (Julia Plotting: delete and modify existing lines),它显示了一种使用 pop! 删除最后绘制的东西的方法,但是这段代码没有运行(如果我将场景添加为 scatter!(scene,...) 的参数,则会收到错误消息) .

感谢您的帮助

【问题讨论】:

    标签: plot julia


    【解决方案1】:

    有一个delete!(ax::Axis, plot::AbstractPlot) method,但有点乱,所以举个例子可能会更清楚:

    scene = scatter([0],[0], color="blue", markersize=10)
    # FigureAxisPlot instance
    # scene.plot is the Scatter instance
    
    points2 = scatter!(2:4, 2:4, color="green", markersize=20)
    # Scatter instance
    
    point3 = scatter!([1], [1], color="red", markersize=15)
    # Scatter instance
    
    delete!(scene.axis, points2)
    # green points removed from plot
    
    delete!(scene.axis, scene.plot)
    # original blue point removed from axis,
    # but scene.plot doesn't change
    

    【讨论】:

    • 您好,非常感谢您的回答。这很有效,完全符合我的需要。
    【解决方案2】:

    我过去用来擦除散点图的一部分是使用背景颜色重绘点(我相信白色是默认值)。但是,如果绘图上有多个图层,则可能需要重新绘制要保留的图层,因为覆盖可能会删除下面存在的其他功能:

    julia> 场景 = scatter([0],[0], color="blue", markersize=10)

    julia> 场景 = scatter([0],[0], color="white", markersize=10)

    【讨论】:

    • 您好,感谢您的回答。我测试了你的解决方案,但问题是(正如你已经提到的),白色圆圈覆盖了我情节中的其他东西。我想这个问题必须有不同的解决方案,比如 Matlab 中的删除函数。
    猜你喜欢
    • 2022-11-11
    • 2022-08-23
    • 1970-01-01
    • 2016-01-03
    • 2019-06-23
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多