Change marker colour of pzplot
16 views (last 30 days)
Show older comments
Hello everyone
I'm trying to change the marker color in the pzplot graph. I'm using version 2024b (edit:) and a LiveScript.
Apparently the code below works for a regular script, but doesn't work in a LiveScript. Maybe this is a rendering bug?
Apparently, in this version, a new object(?) called "PZPlot Properties" was introduced, which is great.
Using this new object, I can easily change the size and line thickness of all markers. But I can also only change the colour of all markers. I'd like to change the colours of the markers for the poles and zeros separately.
I tried using the "findobj" method and found, that the PZPlot apparently consists of two Scatter-Plots called "PZPoleScatter" and "PZZeroScatter", and I tried changing the color of the markers in those Scatter plots, but this does not seem to have an effect on the markers.
When I change the colour of the markers using the PZPlot properties Object, I see the color definition of the markers in both scatter plots change, and I can also see that the colours change if I directly access the properties and change the colour, but the plot isn't drawn with those correct colors.
I tried using refresh after changing the values, but that doesn't have any effect either.
See my code below:
s = tf('s');
f = (1 + 1/s)
pzp = pzplot(f);
% See https://ch.mathworks.com/help/ident/ref/controllib.chart.pzplot-properties.html for new PZPlot-properties object
pzp.Responses.MarkerSize = 10;
pzp.Responses.LineWidth = 2;
%pzp.Responses.Color = 'green'; % Changes colour of all markers
oPole = findobj(gca, 'Tag', 'PZPoleScatter');
oPole.MarkerEdgeColor = 'red';
oZero = findobj(gca, 'Tag', 'PZZeroScatter');
oZero.MarkerEdgeColor = 'blue';
rsp = findobj(gca, 'Tag', 'PZPoleScatter'); % read object again to see if properties got changed correctly
I also found the following two topics, but they do not work anymore as there is no "Line" child in the PZPlot object.
4 Comments
Voss
on 27 Jan 2025
"Could you maybe test if the code also doesn't work for you in a LiveScript?"
Unfortunately, my only option to run the code is here in the Answers forum because I don't have a license for any toolbox containing pzplot.
Accepted Answer
Andrew Ouellette
on 27 Jan 2025
Hi Jan,
Starting in 24b, we introduced new chart and response objects for pzplot().
Each model you input to pzplot() will generate a single response object, which allows you to customize the styling for your response graphics. However, you are correct in that you can only pick a single styling for each response, which all graphics belonging to that response will then match. If you want to split the poles & zeros for a model, I recommend creating a pole-only model and a zero-only model.
s = tf('s');
f = (1 + 1/s);
fpoles = tf(1,f.Denominator{1});
fzeros = tf(f.Numerator{1},1);
pzp = pzplot(fpoles,fzeros);
pzp.Responses(1).MarkerSize = 10;
pzp.Responses(1).LineWidth = 2;
pzp.Responses(1).Color = 'r';
pzp.Responses(2).MarkerSize = 10;
pzp.Responses(2).LineWidth = 2;
pzp.Responses(2).Color = 'b';
Live scripts are a bit of an edge case when it comes to graphics. You'll find that the same behavior occurs when you save & load a figure containing a PZPlot- your changes made using findobj will be obliterated. Using findobj in this manner to change graphics within a PZPlot never notifies the chart object, and thus your changes cannot be serialized. Live scripts will only support changes made using our provided chart API.
More Answers (0)
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
