- 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?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 21 Mär. 2019
Beantwortet: MathWorks Support Team
am 25 Mär. 2019
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])
Akzeptierte Antwort
MathWorks Support Team
am 21 Mär. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!