Subplot overwritten with pzplot

4 次查看(过去 30 天)
Globi Hansi
Globi Hansi 2020-6-17
编辑: Raag 2025-7-1
Good Morning
I'm trying to display system poles nicely using pzmap(). There's a problem (see minimal code below):
Fig1: The plots stack, as expected.
Fig2: Using subplot instead, no overwriting with plot() as expected.
Fig3: Using subplot with pzmap(). Overwrites the previous data for some reason. Why?
Fig4: Same issue when using a loop instead.
Due to the different axis layout? How to prevent this? Wasting too much time here, I should probably just use separate figures instead. The function structure is used because I'm passing parametres to generate seperate state space systems within the function. Might use a loop instead, but there's the same problem. (R2019b)
EDIT:
The other subplot tiles would contain different data, so it's not about the third subplot argument.
ss1 = ss(1,1,1,1,0.05);
ss2 = ss(2,3,1,1,0.05);
figure
plotPZStuff(ss1)
hold on
plotPZStuff(ss2)
legend
figure
plotNormally_subplot(randn(1, 100))
hold on
plotNormally_subplot(randn(1, 100))
legend
figure
plotPZStuff_subplot(ss1)
hold on
plotPZStuff_subplot(ss2)
legend
figure
ssList = [ss1 ss2];
for i = 1:2
ss = ssList(i);
subplot(1,2,1)
pzmap(ss)
end
legend
function plotPZStuff(ss)
pzmap(ss)
end
function plotNormally_subplot(val)
subplot(1,2,1)
hold on
plot(val)
end
function plotPZStuff_subplot(ss)
subplot(1,2,1, 'align')
% subplot(1,2,1)
hold on
pzmap(ss)
end

回答(1 个)

Raag
Raag 2025-7-1
编辑:Raag 2025-7-1
Hi Globi,
As per my understanding, the issue you are facing is due to how ‘pzmap()’ behaves when used inside a subplot. Unlike ‘plot()’, which respects the current axes, ‘pzmap()’ creates a new axes object by default. This causes it to overwrite the existing subplot, even if ‘hold on’ is used.
To prevent ‘pzmap()’ from overwriting the subplot, you can explicitly pass the axes handle to it. Here is how you can modify your function:
function plotPZStuff_subplot(ss)
ax = subplot(1,2,1); % Get handle to the subplot axes
hold(ax, 'on') % Hold on for that specific axes
pzmap(ax, ss) % Pass the axes handle to pzmap
end
This ensures that ‘pzmap()’ plots into the correct subplot without creating a new axes object.
The output will look like this:
For more details, refer:

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by