如何更改绘图中的标记
How to change the marker in a plot
我的问题是关于这段代码的:
w = linspace(-5,5,1000);
figure
for alpha = -1:0.2:1
delay = (alpha.*cos(w)-alpha^2)./(1-2*alpha.*cos(w)+alpha^2);
plot(w,delay)
hold on
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
我想知道是否可以在每次迭代中更改图形的类型。例如,一次是圆圈 ('o-'),一次是钻石 ('d-'),等等
感谢您的回复。
试试这个:
w = linspace(-5,5,1000);
alpha = -1:0.2:1;
shapes = '+o*.xsd^v><ph';
figure, hold on
for ii=1:numel(alpha)
delay = (alpha(ii).*cos(w)-alpha(ii)^2)./(1-2*alpha(ii).*cos(w)+alpha(ii)^2);
plot(w,delay,[shapes(ii),'-'])
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
在这个图中,点靠得太近了,你无法真正拼出形状。您可以通过先绘制不带标记的线来减少标记的数量,然后绘制仅使用标记的二次采样版本:
w = linspace(-5,5,1000);
alpha = -1:0.2:1;
figure, hold on
shapes = '+o*.xsd^v><ph';
cols = jet(numel(alpha));
for ii=1:numel(alpha)
delay = (alpha(ii).*cos(w)-alpha(ii)^2)./(1-2*alpha(ii).*cos(w)+alpha(ii)^2);
plot(w,delay,'-','color',cols(ii,:))
plot(w(1:50:end),delay(1:50:end),shapes(ii),'color',cols(ii,:))
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
如果行数大于可用标记数,上面的代码将抛出索引错误。您可以使用 mod
来循环标记。将 shapes(ii)
替换为
shapes(mod(ii-1,numel(shapes))+1)
我的问题是关于这段代码的:
w = linspace(-5,5,1000);
figure
for alpha = -1:0.2:1
delay = (alpha.*cos(w)-alpha^2)./(1-2*alpha.*cos(w)+alpha^2);
plot(w,delay)
hold on
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
我想知道是否可以在每次迭代中更改图形的类型。例如,一次是圆圈 ('o-'),一次是钻石 ('d-'),等等
感谢您的回复。
试试这个:
w = linspace(-5,5,1000);
alpha = -1:0.2:1;
shapes = '+o*.xsd^v><ph';
figure, hold on
for ii=1:numel(alpha)
delay = (alpha(ii).*cos(w)-alpha(ii)^2)./(1-2*alpha(ii).*cos(w)+alpha(ii)^2);
plot(w,delay,[shapes(ii),'-'])
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
在这个图中,点靠得太近了,你无法真正拼出形状。您可以通过先绘制不带标记的线来减少标记的数量,然后绘制仅使用标记的二次采样版本:
w = linspace(-5,5,1000);
alpha = -1:0.2:1;
figure, hold on
shapes = '+o*.xsd^v><ph';
cols = jet(numel(alpha));
for ii=1:numel(alpha)
delay = (alpha(ii).*cos(w)-alpha(ii)^2)./(1-2*alpha(ii).*cos(w)+alpha(ii)^2);
plot(w,delay,'-','color',cols(ii,:))
plot(w(1:50:end),delay(1:50:end),shapes(ii),'color',cols(ii,:))
end
grid on
xlabel('$\omega$', 'interpreter', 'latex')
如果行数大于可用标记数,上面的代码将抛出索引错误。您可以使用 mod
来循环标记。将 shapes(ii)
替换为
shapes(mod(ii-1,numel(shapes))+1)