【问题标题】:Plot on the same figure in Matlab在 Matlab 中绘制相同的图形
【发布时间】:2013-11-05 20:18:11
【问题描述】:

我有以下代码:

clc
clear
x=[1 2.5 2 3 5 6 3.5 2.1 4 .5]
y=[1 3 1.5 2 1.4 5 3.8 2.1 3 3.5]
p=plot(x,y,'r.')
set(p,'MarkerSize',30)
reg=polyfit(x,y,2)
p2=plot(reg)

如何在同一个图中显示两个图,并且我希望轴范围在 0 到 10 之间。

【问题讨论】:

    标签: matlab plot zooming axis figure


    【解决方案1】:

    我认为这是你真正想做的:

    x=[1 2.5 2 3 5 6 3.5 2.1 4 .5];
    [x, inds] = sort(x);
    y=[1 3 1.5 2 1.4 5 3.8 2.1 3 3.5];
    y = y(inds);
    
    p=plot(x,y,'r.');
    set(p,'MarkerSize',30)
    set(gca,'XLim',[0 10])
    
    reg=polyfit(x,y,2);
    hold on
    plot(x, polyval(reg, x))
    

    【讨论】:

      【解决方案2】:

      http://www.mathworks.com/help/matlab/ref/hold.html

      "hold on;"
      

      hold on 保留当前图表并向其中添加另一个图表。 MATLAB 会根据需要调整坐标区范围、刻度线和刻度标签,以显示添加的图形的整个范围。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多