Matlab – How To Specify a Grid Lines Color Matlab

gridMATLABmatlab-figure

I want to show a grid in Matlab using Meshgrid with specify lines color ( or any Different method ) , My code is :

figure(1)
X = [-1:0.5:1];
Y= [-1:0.5:1];
[X,Y] = meshgrid(X,Y)
plot(X,Y,'k-')
hold on
plot(Y,X,'k-');

this code show all line with black color, but i want to show some lines with different color like this :

figure(1)
X = [-1:0.5:1]; % with black color
X = [-1:0.2:1]; % with red color
Y= [-1:0.5:1]; % with black color
Y= [-1:0.2:1]; % with red color

how to do that ?

Best Answer

just use different color specification when calling plot:

X = [-1:0.5:1]; % with black color
x = [-1:0.2:1]; % with red color
Y= [-1:0.5:1]; % with black color
y= [-1:0.2:1]; % with red color

[X,Y] = meshgrid(X,Y);
[x,y] = meshgrid(x,y);
plot(X,Y,'k-','Linewidth',2)
hold on
plot(Y,X,'k-','Linewidth',2);
plot(x,y,'r-');
plot(y,x,'r-');

enter image description here

Related Topic