- You can change this behavior using the 'hold' command,
- You can manually toggle the NextPlot property to 'replacechildren' or 'add' (this is how 'hold on' is implemented).
Why does creating a new plot reset my axes properties?
조회 수: 12 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2019년 3월 21일
답변: MathWorks Support Team
2019년 3월 25일
I am running into an issue where I set some axes properties in my figure window, but then when I go to plot the axes is reset to it's default properties. Why is this happening?
How can I set the axes properties before plotting and have them stay in effect?
Please see the following simplified reproduction code:
f = figure();
ax = axes(f);
ax.Tag = 'MyAxesTag';
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
disp(['The Axes Tag before scatter3 is: ', ax.Tag])
scatter3(ax,x,y,z)
disp(['The Axes Tag after scatter3 is: ', ax.Tag])
채택된 답변
MathWorks Support Team
2019년 3월 21일
This behavior is expected, the 'plot' command resets the axes properties before plotting.
There are two ways of resolving this:
% Example 1 - Using the hold command
f = figure();
ax = axes(f);
ax.Tag = 'MyAxesTag';
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
disp(['The Axes Tag before scatter3 is: ', ax.Tag])
hold(ax,'on')
scatter3(ax,x,y,z)
disp(['The Axes Tag after scatter3 is: ', ax.Tag])
The hold command allows for the retention of the current plots when creating new plots. For more information, please see:
% Example 2 - using the NextPlot property
f = figure();
ax = axes(f);
ax.Tag = 'MyAxesTag';
[X,Y,Z] = sphere(16);
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
disp(['The Axes Tag before scatter3 is: ', ax.Tag])
ax.NextPlot = 'add'
scatter3(ax,x,y,z)
disp(['The Axes Tag after scatter3 is: ', ax.Tag])
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!