Skip to content

Instantly share code, notes, and snippets.

@mdaddysman
Created September 27, 2017 14:38
Show Gist options
  • Save mdaddysman/165f0056b19cd59e954d242e05dca8de to your computer and use it in GitHub Desktop.
Save mdaddysman/165f0056b19cd59e954d242e05dca8de to your computer and use it in GitHub Desktop.
Simple code for adding continuous color scale to a line plot in Matlab
%generate a set of offset lines
nlines = 10;
t = 1:nlines;
for m=1:nlines
x(:,m) = t+m;
end
figure %plot all the lines in the default colors
h(1) = plot(t,x(:,1));
hold on
for m=2:nlines
h(m) = plot(t,x(:,m));
end
hold off
clist = parula(nlines); %generate a color map equal to the number of lines
for m=1:nlines
h(m).Color = clist(m,:); %update the color of the lines
end
colorbar %display a colorbar next to the plot
caxis([1 nlines]) %update the color axis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment