将图形设置为不作为下一个绘图的目标
Set figure to not be target for next plot
我正在开发带有一些图表的自定义进度监视器。我注意到 Matlab 的 waitbar
创建了一个具有一些特殊属性的图形,所以如果你这样做
plot(rand(100,1));
wb = waitbar(0);
plot(rand(100,1));
第二个情节最终取代了第一个情节,而不是 wb
。 是否有 属性 我可以设置,以便当我创建我的进度监视器然后绘制一些东西时,图表不会出现在我的图中?
为了清楚起见,我正在努力
plot(rand(100,1));
temp = MyProgressBar();
plot(rand(100,1));
为第一个绘图创建一个图形,在第二行创建一个不同的图形,然后在第三行绘制一个新图形。
为了保护您的进度条图形不受后续绘图操作的影响,我会设置 'HandleVisibility'
property of its axes to 'off'
. That should prevent it ever becoming the current axes, thus keeping subsequent plotting commands from modifying or adding to it. It's a good practice for stand-alone figures/GUIs in general that you turn off the handle visibility of all objects (figure, uicontrols, etc.) in this way to insulate them against being modified by outside code. This is almost certainly what is done in the code for waitbar
。
另外,最好先通过 passing the axes handle as the first argument. You also have to make sure that, if you want new plots to be added to existing plots, you use things like the hold
命令将绘图定位到给定的坐标轴。假设您希望这两个图出现在同一轴上,我将如何修改您的示例:
plot(rand(100,1)); % Creates new figure and axes
hAxes = gca; % Get the axes handle
hold on; % Allow subsequent plots to be added
temp = MyProgressBar();
plot(hAxes, rand(100,1)); % Will be added to the first plot axes
我正在开发带有一些图表的自定义进度监视器。我注意到 Matlab 的 waitbar
创建了一个具有一些特殊属性的图形,所以如果你这样做
plot(rand(100,1));
wb = waitbar(0);
plot(rand(100,1));
第二个情节最终取代了第一个情节,而不是 wb
。 是否有 属性 我可以设置,以便当我创建我的进度监视器然后绘制一些东西时,图表不会出现在我的图中?
为了清楚起见,我正在努力
plot(rand(100,1));
temp = MyProgressBar();
plot(rand(100,1));
为第一个绘图创建一个图形,在第二行创建一个不同的图形,然后在第三行绘制一个新图形。
为了保护您的进度条图形不受后续绘图操作的影响,我会设置 'HandleVisibility'
property of its axes to 'off'
. That should prevent it ever becoming the current axes, thus keeping subsequent plotting commands from modifying or adding to it. It's a good practice for stand-alone figures/GUIs in general that you turn off the handle visibility of all objects (figure, uicontrols, etc.) in this way to insulate them against being modified by outside code. This is almost certainly what is done in the code for waitbar
。
另外,最好先通过 passing the axes handle as the first argument. You also have to make sure that, if you want new plots to be added to existing plots, you use things like the hold
命令将绘图定位到给定的坐标轴。假设您希望这两个图出现在同一轴上,我将如何修改您的示例:
plot(rand(100,1)); % Creates new figure and axes
hAxes = gca; % Get the axes handle
hold on; % Allow subsequent plots to be added
temp = MyProgressBar();
plot(hAxes, rand(100,1)); % Will be added to the first plot axes