필터 지우기
필터 지우기

How to apply "hold" to some but not all plot objects

조회 수: 12 (최근 30일)
KAE
KAE 2017년 6월 16일
댓글: KAE 2017년 6월 20일
Is there a way to apply "hold on" to some plot objects, but to apply "hold off" to other objects in the same plot?
The example below plots a pcolor object then several lines. I want the pcolor object to remain plotted as if it were "hold on", but as each new line is plotted, I want the old line to disappear, as if the lines were "hold off". (At the time I wrote this, I thought deleting the line handle h2 was not an option: the real code is buried in a GUI currentpoint function which seems to prevent me from accessing h2.)
% Make an example plot
figure;
p = peaks; % Get 'peaks' data which comes with Matlab
[nY, nX] = size(peaks);
x = 1:nX; y = 1:nY;
h1 = pcolor(x, y, peaks); % Want pcolor object to remain
shading flat;
hold on; % Applies to all plotted objects
title('Wish we could hold pcolor but not lines')
% Plot several lines over top of pcolor plot
nLine = 10; % Number of lines to plot
for iLine = 1:(nLine)
h2 = plot(rand(1,10)*nX, rand(1,10)*nY, 'ko-');
% Want 'old' h2 to disappear when 'new' h2 plotted
pause(1); % Allow user to see lines being plotted
end

채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 16일
Sorry, hold is per axes. But that means that you could put the pcolor up in a different axes at the same position
For this sort of work a better approach is to update the xdata and ydata properties of the line object instead of creating and deleting objects all the time.

추가 답변 (1개)

KAE
KAE 2017년 6월 16일
편집: KAE 2017년 6월 16일
Jan Simon's answer here actually solved the problem, though not as I stated it: it allowed me to access the line handle which I could then delete. But if it is possible to apply the "hold on" or "hold off" option to specific plot objects, I'd still like to know.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by