MATLAB: How to change the legend color

change color

n = 2/3;
A = 1;
r = linspace(0,0.4,30);
th = linspace(0,2*pi,100);
[R, TH] = meshgrid(r,th);
fi = A*R.^n.*cos(n*TH);
zi = A*R.^n.*sin(n*TH);
[X,Y] = pol2cart(TH,R);
contour(X,Y,fi,'r')
hold on
contour(X,Y,zi,'b')
hold off
xlabel x-axis
ylabel y-axis
title('n = 2/3: flow around a right corner')
legend('\phi','\psi')

Best Answer

First, create a handle to the legend object, then change whatever properties you want using the options in Legend Properties.
Example (with your code) —
n = 2/3;
A = 1;
r = linspace(0,0.4,30);
th = linspace(0,2*pi,100);
[R, TH] = meshgrid(r,th);
fi = A*R.^n.*cos(n*TH);
zi = A*R.^n.*sin(n*TH);
[X,Y] = pol2cart(TH,R);
contour(X,Y,fi,'r')
hold on
contour(X,Y,zi,'b')
hold off
xlabel x-axis
ylabel y-axis
title('n = 2/3: flow around a right corner')
hl = legend('\phi','\psi');
set(hl, 'TextColor','r', 'Color','g', 'EdgeColor','b')
Experiment to get the result you want.