Setting colors for plot function in Matlab

I would like to be able to choose colors for a multi-line plot, but I cannot get it. This is my code.

colors = {'b','r','g'}; T = [0 1 2]'; column = [2 3]; count = magic(3); SelecY = count(:,column), plot(T,SelecY,'Color',colors{column}); 
+4
source share
2 answers

You can specify only one color at a time, and it should be specified as a vector with three RGB elements. Your three routes:

  • Scroll and specify the colors along the line, for example, you have:

     hold on for i=1:size(SelecY, 2) plot(T, SelecY(:,i), colors{i}); end 
  • Using the RGB color specification, you can convey colors through the Color property, as you tried to do above:

     cols = jet(8); hold on for i=1:size(SelecY, 2) plot(T, SelecY(:,i), 'Color', cols(i,:)); end 
  • Also, using the RGB method, you can specify a ColorOrder in front, and then skip the Matlab loop through:

     set(gca, 'ColorOrder', jet(3)) hold all for i=1:size(SelecY, 2) plot(T, SelecY(:,i)); end 

To adjust colors after the fact, see another answer.

+3
source

For some reason, I could not get it to work without using a descriptor, but:

 h = plot(T,SelecY); set(h, {'Color'}, colors(column)'); 

It works for me.

+4
source

Source: https://habr.com/ru/post/1379559/


All Articles