Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of multiple freqz plots?

I am plotting multiple frequency responses on the same plot using "hold" and "freqz" in MATLAB. Is there any way to adjust the color of each plot so I can identify which one is which? Right now it looks like a mess.

enter image description here

Freqz doesn't appear to support changing the plot's color like "plot" does.

like image 291
codedude Avatar asked Oct 31 '25 13:10

codedude


1 Answers

It's indeed a little tricky as freqz does not provide a handle.

b = fir1(80,0.5,kaiser(81,8));
freqz(b,1); hold on
c = fir1(80,0.9,kaiser(81,8));
freqz(c,1); hold on

But you can get them by using findall:

lines = findall(gcf,'type','line');

and then color the lines as usual:

lines(1).Color = 'red'
lines(2).Color = 'green'
lines(3).Color = 'red'
lines(4).Color = 'green'

or for Matlab versions prior to 2014b:

set(lines(1),'Color','red')
set(lines(2),'Color','green')
set(lines(3),'Color','red')
set(lines(4),'Color','green')

It works for all LineSpec properties.

enter image description here

like image 142
Robert Seifert Avatar answered Nov 03 '25 08:11

Robert Seifert