필터 지우기
필터 지우기

For a known number of plots on the same axis, how do I set the colourscale?

조회 수: 3 (최근 30일)
Em
Em 2024년 3월 5일
댓글: Voss 2024년 3월 9일
I'm trying to plot my 20 results with a span of rainbow colours and was wondering how you could go about doing this using matlab? Thanks!

채택된 답변

Voss
Voss 2024년 3월 5일
data = (1:100).'+(1:20);
n_lines = size(data,2);
colors = jet(n_lines);
figure
colororder(colors);
plot(data)
  댓글 수: 4
Em
Em 2024년 3월 9일
Hi, thank you for this! It's working well. If you don't mind, there is one more thing I'd really appreciate your help with. The colourscale has started repeating itself at some point due to the number of measurements (see image). Do you know how I could stop this from happening?
Voss
Voss 2024년 3월 9일
If the colors are repeating, to prevent that from happening, use (at least) as many colors as you have lines.
  • If the number of lines is known in advance of plotting, construct the colormap with that many lines, as shown in my previous comment where I used a jet colormap with 8 colors to color 8 lines.
  • If the number of lines is not known in advance or changes as the code runs, you'll have to update the set of colors and apply that to colororder.
However, are you sure the colors are repeating? From the screen shot, I cannot say for sure that's what's happening. It may just be that the line color order is not the same as the line order in the y-direction on the plot. For example, if the first line you plot is of the first color in the colormap and is the bottommost (lowest y) line on the plot, the second line is of the second color and is the second-lowest line, and so on, then yes, it looks like the lines are out of order with what might be a typical colormap. But I don't know that the lines are in that order in terms of the y on the plot, and I don't know what the colormap is.
If you are already using (at least) as many colors as lines, or changing that doesn't fix the problem, please share some code I can run to take a look.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by