How can I specify to which figure a plot should go?

前端 未结 2 1418
暗喜
暗喜 2021-02-12 22:36

I have multiple figures open, and I want to update them independently during runtime. The following toy example should clarify my intention:

clf;

figure(\'name         


        
2条回答
  •  长发绾君心
    2021-02-12 22:46

    You can specify the axes-object in the plot-command. See here:

    http://www.mathworks.de/help/techdoc/ref/plot.html

    So, open a figure, insert the axes, save the id of the axes object, and then plot into it:

    figure
    hAx1 = axes;
    plot(hAx1, 1, 1, '*r')
    hold on
    
    figure
    hAx2 = axes;
    plot(hAx2, 2, 1, '*r')
    hold on
    
    
    plot(hAx2, 3, 4, '*b')
    plot(hAx1, 3, 3, '*b')
    

    Alternatively, you can use gca instead of creating the axes object yourself (because it's automatically created within the actual figure, when it doesn't exist!)

    figure
    plot(1,1)
    hAx1 = gca;
    hold on
    
    figure
    plot(2,2)
    
    plot(hAx1, 3, 3)
    

    See the following hierarchy representing the relationship between figures and axes

    enter image description here

    From http://www.mathworks.de/help/techdoc/learn_matlab/f3-15974.html.

提交回复
热议问题