Julia Plotting: delete and modify existing lines

前端 未结 3 2015
孤街浪徒
孤街浪徒 2021-01-13 01:31

Two questions in one: Given a line plotted in Julia, how can I

  1. delete it from the plot and legend (without clearing the whole plot)
  2. change its propert
3条回答
  •  灰色年华
    2021-01-13 02:25

    I have to say that I don't know what the formal way is to accomplish them.

    There is a cheating method.

    plt.series_list stores all the plots (line, scatter...).
    If you have 200 lines in the plot, then length(plt.series_list) will be 200.

    plt.series_list[1].plotattributes returns a dictionary containing attributes for the first line(or scatter plot, depends on the order).

    One of the attributes is :linealpha, and we can use it to modify the transparency of a line or let it disappear.

    # your code ...
    
    plot!(0:.1:1, x->coefs[2]*x+coefs[1], c=:blue)  # plot new regression line
    
    # modify the alpha value of the previous line
    if i > 1
        plt.series_list[end-1][:linealpha] = 0.1
    end
    
    # make the previous line invisible
    if i > 2
        plt.series_list[end-2][:linealpha] = 0.0
    end
    
    frame(anim)
    # your code ...
    

提交回复
热议问题