gpt4 book ai didi

Matlab:在循环中绘制带有保持和保持关闭的子图,而不总是调用 xlabel、ylabel、xlim 等

转载 作者:行者123 更新时间:2023-12-02 07:02:34 25 4
gpt4 key购买 nike

Matlab 问题:这可能非常简单,但我无法弄清楚......我很新。我有一个绘图窗口,分为两个子图,我们称它们为 A 和 B,它们具有不同的标签和限制。我(坚持),对 B 绘制几个图,然后我(坚持),然后开始迭代。在循环中,我想用新图更新 A 和 B,但我希望轴标签以及 xlim 和 ylim 保持不变,而不必每次迭代都调用 xlabel、xlim 等。

现在,(拖延)会破坏所有轴属性。如何保存轴属性,以便不必在循环中继续调用 xlabel 等?我尝试过 newplot、设置 Nextplot 属性等均无济于事。我想要一个简单的解决方案...而不是重写绘图命令之类的东西。谢谢!

hfig=figure();
hax = axes('Parent',hfig);
plot(hax,x,y);
hold on
plot(hax,x1,y1);
%this hold off resets the axes
hold off
while (1)
subplot('Position',[.07 .05 .92 .44]);
%I want to do this without having to call xlabel, ylabel, etc
%over and over
plot(newx, newy);
xlabel()
ylabel()
hold on
plot(newx1, newx2)
hold off
...
end

最佳答案

这里的一个解决方案是在循环之前初始化绘图和轴属性,然后在循环中设置 'NextPlot' property的轴到'replacechildren',以便在下次调用 PLOT 时仅更改绘图对象(而不是轴设置):

hFigure = figure();
hAxes = axes('Parent',hFigure);
plot(hAxes,x,y);
hold on;
plot(hAxes,x1,y1);
xlabel(...); %# Set the x label
ylabel(...); %# Set the y label
xlim([...]); %# Set the x limits
ylim([...]); %# Set the y limits
while (1)
set(hAxes,'NextPlot','replacechildren');
plot(hAxes,newx,newy);
hold on;
plot(hAxes,newx1,newx2);
...
end

当在循环中绘制新数据时,这应该保持 hAxes 的设置。

关于Matlab:在循环中绘制带有保持和保持关闭的子图,而不总是调用 xlabel、ylabel、xlim 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5480030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com