使轴不可见或完全删除绘图 [英] make axes invisible or delete plot completely
问题描述
我有一个matlab gui,其中应包含4个地块.如果在列表中选择了其他文件,则应更新第一幅图.其他3个仅应要求可见(并计算).
I have a matlab gui that shall contain 4 plots. The first plot shall be updated if a different file is selected in a list. the other 3 shall only be visible (and be calculated) on request.
但是,一旦绘制了2-4个图,我就无法使它不可见.
However I fail to make plots 2-4 invisible after they have been plotted once.
我尝试了
set(handles.axesImage, 'Visible', 'off');
但这只会删除轴,不会删除整个图.
but that only deletes the axis, not the whole plot.
除了使事物不可见之外,还可以实际删除内容吗?通常,我会打电话给close(hfig);
,但是在这里我没有数字.
Instead of making things unvisible, is it also possible to actually delele the content? Typically I would call close(hfig);
, but here i have no figure.
我尝试了
handles2hide = [axisObj;cell2mat(get(axisObj,'Children'))];
delete(handles2hide);
但是对于未绘制的轴(启动后),该操作将失败
But that fails for the unplotted axes (after startup)
我将代码更改为:
axisObj = handles.axesContour;
if ishandle(axisObj)
handles2delete = get(axisObj,'Children');
delete(handles2delete);
set(axisObj,'visible','off')
end
if (isfield(handles,'contour') && isfield(handles.contour,'hColorbar'))
delete(handles.contour.hColorbar);
delete(handles.contour.hColorbarLabel);
end
但是,颜色栏仍保持未删除状态,并且handles.contour.hColorbar
失败,并显示Invalid handle object.
However the colorbar remains undeleted and handles.contour.hColorbar
fails with Invalid handle object.
推荐答案
我现在用
function z_removePlots(handles)
if (isfield(handles,'image') && isfield(handles.image,'hplot'))
if ishandle(handles.image.hplot)
delete(handles.image.hplot);
delete(findall(gcf,'tag','Colorbar'));
handles.image.hplot = 0;
set(handles.axesImage, 'Visible', 'off');
end
end
if (isfield(handles,'contour') && isfield(handles.contour,'hplot'))
if ishandle(handles.contour.hplot)
delete(handles.contour.hplot);
handles.contour.hplot = 0;
ClearLinesFromAxes(handles.axesContour)
set(handles.axesContour, 'Visible', 'off');
end
end
guidata(handles.output,handles);
与
function ClearLinesFromAxes(axisObj)
if ishandle(axisObj)
handles2delete = get(axisObj,'Children');
delete(handles2delete);
end
这篇关于使轴不可见或完全删除绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!