Created
September 27, 2017 14:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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