多个图的pzmap或pzplot颜色句柄 [英] pzmap or pzplot color handle for multiple plots
问题描述
我正在使用 pzmap.m 或 pzplot.m 中的任意一个绘制系统的闭环极点.我想在更改由 L 表示的变量时看到极点和零点的运动.
I am plotting a closed loop poles of a systems using pzmap.m or pzplot.m whichever you prefer. I want to see the movement of poles and zeros as I change a variable depicted by L.
该功能没有颜色的直接句柄.在示例中,您只能选择标准颜色,而不能给出自己的颜色.由于必须在同一图形上绘制多次,因此我为 for 循环中的每次迭代创建一个句柄,并使用 findobj 设置曲线的颜色.为了获得颜色,我想要一个 colorbar .因此,我使用 jet 来获取图形的颜色分布.但是市场规模保持不变,而且我有一个难看的数字.
The function does not have a direct handle for color. In the example you can just choose the standard colors but cannot give your own color. Since I have to plot multiple times on the same figure, I create a handle for every iteration in a for loop and use findobj to set the color of the curve. To get the colors I want to have a colorbar. So I use jet to get the color distribution for my graph. But the market size stays the same and I have one ugly looking figure.
MWE:
cb=jet(10);
s=tf('s');
L_array=5:5:50;
figure; hold on;
for i=1:length(L_array)
L=L_array(i);
G=((58.2+11.7*L)*s^2*25^2+(3996.8 + 815.7*L)*s*25+815.7*25^2)/(s^2*(s^2*25^2+126.9*s*25+(3996.8+1.9*25^2)));
CL=feedback(G,1);
pzmap(CL);
h = findobj(gcf,'type','point'); set(h,'markers',12,'color',cb(i,:));
clear L G CL h
end
grid;
c=colorbar
c.Label.String = 'L'
如果运行它,您会发现大小没有改变,并且图形看起来很疯狂,并且y轴的两侧都标有刻度.我想要一个合适的 colorbar (从蓝色到红色),并且颜色分配正确,但是多次尝试后却无法获得它.如果我可以减少混乱,那也会有所帮助.
If you run it you'll see that the size doesn't change and graph looks crazy with the y axis on either side labelled with ticks. I want a proper colorbar from blue to red and the colors distributed properly but can't get it after multiple tries. If I can get less cluttering that would be helpful too.
推荐答案
代码中有几个问题
-
h = findobj(gcf,'type','point');
屏幕上绘制的内容实际上是'line'
类型! - 每次迭代时,您都会捕获所有点,并在删除属性后以明确的方式对其进行修改.
h = findobj(gcf,'type','point');
The things drawn in the screen are actually of type'line'
!- Every iteration, you catch all the points, modify them an dimdediately after delete the properties with clear.
此外,h = findobj(gcf,'type','line');
不会返回任何东西,而是返回它们的集合,因此您需要对其进行索引以设置属性.我修改后的代码工作如下:
Additionally, h = findobj(gcf,'type','line');
will not return a single thing, but a set of them, so you need to index through it to set the properties. My modified code working looks like this:
clear;clc
cb=parula(10);
s=tf('s');
L_array=5:5:50;
figure; hold on;
for i=1:length(L_array)
L=L_array(i);
G=((58.2+11.7*L)*s^2*25^2+(3996.8 + 815.7*L)*s*25+815.7*25^2)/(s^2*(s^2*25^2+126.9*s*25+(3996.8+1.9*25^2)));
CL=feedback(G,1);
pzmap(CL);
end
% lets do this in the end!
% you will have length(L_array)*2 +1 items in h
h = findobj(gca,'type','line');
for jj=2:length(h)
set(h(jj),'MarkerSize',12,'Color',cb(floor(jj/2),:));
end
grid;
colormap(parula); % I am using parula, you can use jet, but I discourage it
c=colorbar;
PD:有很多原因不使用jet
!请使用可感知的统一颜色图!
PD: there are tons of reasons not to use jet
!! Use perceptually uniform colormaps please!
这篇关于多个图的pzmap或pzplot颜色句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!