How to make a line plot with Jet colored lines?

Hi everyone!
I would like to make a line plot of the attached data. There are about 64 different lines in the single plot.
So, I use the following command.
zz1.zz1 = load('z1.mat');
zz1.zz2 = load('x2.mat');
plot(zz1.zz2.X2_axis, zz1.zz1.Z2_axis)
I get the following attached figure.
Instead I want the lines to follow jet colorbar.
Something like
cmp1 = colorbar(jet(64));
plot(zz1.zz2.X2_axis, zz1.zz1.Z2_axis,'Color',cmp1);
But, this throws error!
Any help will be greatly appriciated.

 Accepted Answer

zz1.zz1 = load('z1.mat');
zz1.zz2 = load('x2.mat');
cmp1 = jet(64);
% Use colororder
colororder(cmp1);
plot(zz1.zz2.X2_axis, zz1.zz1.Z2_axis);
h=gca;
legend(h.Children, 'Location', 'Eastoutside', 'NumColumns', 2, 'FontSize', 6)

15 Comments

colororder() is new as of R2019b. For versions before that, set the axes ColorOrder property to jet(64)
Thank you so much! It worked. But, could you please tell me
What is the meaning of :
Warning: Limiting legend entries to 50. Specify a vector of graphics objects to display more than 50 entries.
> In legend>process_inputs (line 559)
In legend>make_legend (line 315)
In legend (line 259)
There is a default of max number (50) of legends. If the number of legends is greater than 50, you need to specify the handles to your graph object. The code has been updated bu using the children of the current axes, or the 64 line plots.
Thanks @Chunru, it did a great help.
MP
MP on 17 Aug 2022
Edited: MP on 17 Aug 2022
@Walter Roberson: I have 2021a, when i use ColorOrder it shows following error:
Cannot find an exact (case-sensitive) match for 'ColorOrder'
The closest match is: colororder in C:\Program Files\MATLAB\R2021a\toolbox\matlab\graphics\color\colororder.m
Did you mean:
>> colororder(cmap1);
for earlier versions, you should use:
set(gca, 'ColorOrder', cmap1)
You can use the colororder() function in R2021a; the 'ColorOrder' property is needed for versions up to R2019a
How to give the attached matrix as legend labels instead of data1, data2, data3, ..., data64 legend labels?
Could you please tell?
Are you sure? That file contains Y2axis_3 which is a 1 x 64 double, such as 0.0201731696724892 0.0213236194103956 0.0226981732994318 . Are you sure you want those as the labels? If so then how many digits should they be rounded to for the legend purpose ?
SN = compose("%.4f", Y2axis_3);
legend(h.Children, SN, 'Location', 'Eastoutside', 'NumColumns', 2, 'FontSize', 6)
@Chunru: what did colororder do to my legend entires?
Why is it reversed?
Red is maximum value, but in legend it corresponds to minimum value!!
Could you please chcek that?
The legend displays items in order of creation, not in order of values.
If you want to change that, you need to determine some number for each line, and use the second output of the sort function to sort the legend entries in the command Walter showed you.
@Rik Certainly, I have used the code given by walter.
I know that the legend entires appear in the plotting sequence and my sequence starts from lower values.
You can flip SN or h.Children. Alternatively, use a loop:
for i=1:size(zz1.zz1.Z2_axis, 2)
plot(zz1.zz2.X2_axis(:, i), zz1.zz1.Z2_axis(:,i), 'DisplayName', SN(i));
end
% Assume that SN is string array
Yes, that is perfect. @Chunru
Thank you very much.

Sign in to comment.

More Answers (0)

Asked:

MP
on 17 Aug 2022

Commented:

MP
on 18 Aug 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!