You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to make a line plot with Jet colored lines?
32 views (last 30 days)
Show older comments
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
Chunru
on 17 Aug 2022
Edited: Chunru
on 17 Aug 2022
15 Comments
Walter Roberson
on 17 Aug 2022
colororder() is new as of R2019b. For versions before that, set the axes ColorOrder property to jet(64)
MP
on 17 Aug 2022
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)
Chunru
on 17 Aug 2022
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.
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);
Walter Roberson
on 17 Aug 2022
You can use the colororder() function in R2021a; the 'ColorOrder' property is needed for versions up to R2019a
MP
on 17 Aug 2022
How to give the attached matrix as legend labels instead of data1, data2, data3, ..., data64 legend labels?
Could you please tell?
Walter Roberson
on 17 Aug 2022
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 ?
Walter Roberson
on 17 Aug 2022
SN = compose("%.4f", Y2axis_3);
legend(h.Children, SN, 'Location', 'Eastoutside', 'NumColumns', 2, 'FontSize', 6)
Rik
on 18 Aug 2022
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.
Chunru
on 18 Aug 2022
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
More Answers (0)
See Also
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)