How can I create different colors in the plotted chart for a lot of data

209 views (last 30 days)
Hello everyone;
I have huge data set, and i plotted for at least 70 different sets. What should I do to color all lines differently? What are your suggestions?
I thank everyone in advance
  2 Comments
Turlough Hughes
Turlough Hughes on 18 Sep 2020
Edited: Turlough Hughes on 18 Sep 2020
What code do you have so far? The plot function usually varies line colours for you if you haven't specified it.
Abidin Burak Nuzumlali
Abidin Burak Nuzumlali on 19 Sep 2020
Hello, i know this function use varies line colours but i have very big data so after every 8 lines the colors return to the beginning

Sign in to comment.

Accepted Answer

Turlough Hughes
Turlough Hughes on 20 Sep 2020
I'm coming at this from a slightly different angle. You can interactively highlight different lines by setting up a slider in the live editor as per the demo I've attached. With this approach you can see all the other data while highlighting one line of interest at a time (in this case I just increase the linewidth and bring it to the front of the graph, though one could specify other line properties).
Advantages: You do not have to read down a list of 70 or more legend entries. You avoid any colour similarity issue, and furthermore, you ensure the line you want to assess is in the foreground; with 70 or more lines it is quite likely that many cover a large portion of the line you’re currently looking at.
  2 Comments
Adam Danz
Adam Danz on 20 Sep 2020
Edited: Adam Danz on 21 Sep 2020
You could also apply datatips that would reveal info about each line when the mouse hovers over the line.

Sign in to comment.

More Answers (2)

Dana
Dana on 18 Sep 2020
Are you trying to plot 70 different data series on the same plot? If so, Matlab's default color scheme won't give you 70 different colors. Instead, there are 7 colors that it cycles through, so you'll end up with 10 data series for each color.
You can create your own color order with as many colors as you want in it, but before you do, let me ask: are you sure you want to do that? 70 plots on one graph is...a lot.
If you're sure, then the easiest way is probably to pick a pre-set color map (see colormap), use it to generate 70 different colors, and then use colororder to apply it to your figure. So if X is a matrix with 70 columns, each containing one data series, something like:
N = size(X,2); % number of data series
plot(X) % plot your data
colororder(parula(N)) % pick N colors from the parula color map and use them
  4 Comments
Adam Danz
Adam Danz on 20 Sep 2020
To add to Dana's answer,
1) Some colormaps only conatain a discrete set of colors with much less than 70 colors so carefully select a colormap with a continuous range of colors. https://www.mathworks.com/help/matlab/ref/colormap.html#buc3wsn-6
2) As Stephen mentioned, you can set the color values directly or you could use Dana's suggestion to use colororder. If you want to apply that directly you can do so within a loop, indexing from the RGB color matrix, or you can apply different colors to a vector of handles using a cell array of RGB values.
3) No matter what colormap you choose, with 70 colors you're going to have lots of colors that are very similar. You could add a legend that defines each color but with 70 lines, the legend will be large and disorganized. Instead, define a colorbar that defines each line.

Sign in to comment.


Adam Danz
Adam Danz on 20 Sep 2020
Inspired by Turlough Hughes's slider used to chose a line object, here's a way to add info to each line's data tip so you can hover the mouse of any line to display the line info.
Here's another demo containing a series of gaussians and I've added the sigma (width) and amplitude (height) of each curve to the data tip. The data tip appears when you hover the mouse over the curve or if you click on the curve.
Modify the demo to add any information you want to the line.
% Plot 12 gaussians with different widths and heights
x = linspace(0,200,1000);
gaus = @(x,mu,sig,amp)amp.*exp(-(((x-mu).^2)./(2.*sig.^2)));
amp = linspace(10,12,8)';
sig = linspace(20,30,8)';
y = gaus(x,100,sig,amp);
h = plot(x,y');
% Add two rows to the data tips to show their sigma (width)
% and amp (height) values.
for i = 1:numel(h)
% Add a new row to DataTip showing the gaus parameters
h(i).DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Sigma',repmat({round(sig(i),2)},size(h(i).XData)));
h(i).DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Amp',repmat({round(amp(i),2)},size(h(i).XData)));
end
Result
  5 Comments
Adam Danz
Adam Danz on 21 Sep 2020
@Turlough Hughes, you're too fair :)
Take the credit for inspiring my idea.
All 3 answers here are viable solutions and may benefit future visitors.
Abidin Burak Nuzumlali
Abidin Burak Nuzumlali on 22 Sep 2020
Turlough Hughes, As Adam Danz said, all 3 solution methods are a very efficient solution method. I have achieved a result by considering all your suggestions and blending them. So instead of comparing each other, I used all the answers.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!