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

조회 수: 207 (최근 30일)
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
Turlough Hughes
Turlough Hughes 2020년 9월 18일
편집: Turlough Hughes 2020년 9월 18일
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 2020년 9월 19일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Turlough Hughes
Turlough Hughes 2020년 9월 20일
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
Adam Danz
Adam Danz 2020년 9월 20일
편집: Adam Danz 2020년 9월 21일
You could also apply datatips that would reveal info about each line when the mouse hovers over the line.
Abidin Burak Nuzumlali
Abidin Burak Nuzumlali 2020년 9월 21일
Thank you for your advice. I solved my problem

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Dana
Dana 2020년 9월 18일
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
Adam Danz
Adam Danz 2020년 9월 20일
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.

댓글을 달려면 로그인하십시오.


Adam Danz
Adam Danz 2020년 9월 20일
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
Adam Danz
Adam Danz 2020년 9월 21일
@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 2020년 9월 22일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by