Sometimes you have to plot a series of functions on the same axes, but if you let MATLAB select the colors for you, you’ll get quite a mess:

Plot without a colormap

If you define a colormap over the range you’re working with, you can create a plot that’s easier to understand:

Plot with a colormap

First you have to create a colormap using a preset you like (a list is available here):

cmap = parula(<NUMBER_OF_POINTS>);

Then you can set the plot colour using the map you’ve created:

hold on;
for ii = 1:<NUMBER_OF_POINTS>
    plot(x, y(ii), 'color', cmap(ii, :));
end
hold off;

You can find the code used to generate both plots at the end of the post.

Enjoy, and remember: friends don’t let friends use jet.

Sample Code Without Colormap:

% Constant definitions
q = 1.6e-19;                   % Electron charge (C)
k_B = 1.80e-23;                % Boltzmann's constant (J/K)
E_F = 0;                       % Fermi energy
E = linspace(-3, 3, 1000);     % Energy range
N_T = 20;                      % Number of temperatures to plot
T = linspace(1e-9, 3000, N_T); % Temperature range

% Plotting Fermi function over temperature range
hold on;
for ii = 1:N_T
    plot(1 ./ (1 + exp((E - E_F) / (k_B * T(ii) / q))), E);
end
hold off;

% Plot options
xlabel('Fermi Function');
xlim([-0.1 1.1]);
ylabel('Energy (eV)');
title('Fermi Function Distribution from 0K to 3000K');
grid on;

Sample Code With Colormap:

% Constant definitions
q = 1.6e-19;                   % Electron charge (C)
k_B = 1.80e-23;                % Boltzmann's constant (J/K)
E_F = 0;                       % Fermi energy
E = linspace(-3, 3, 1000);     % Energy range
N_T = 20;                      % Number of temperatures to plot
T = linspace(1e-9, 3000, N_T); % Temperature range

% Select colormap
cmap = parula(N_T);

% Plotting Fermi function over temperature range
hold on;
for ii = 1:N_T
    plot(1 ./ (1 + exp((E - E_F) / (k_B * T(ii) / q))), E, ...
         'color', cmap(ii, :));
end
hold off;

% Plot options
xlabel('Fermi Function');
xlim([-0.1 1.1]);
ylabel('Energy (eV)');
title('Fermi Function Distribution from 0K to 3000K');
grid on;