필터 지우기
필터 지우기

how to use different color for different segment of same graph?

조회 수: 23 (최근 30일)
safisay
safisay 2017년 11월 13일
댓글: Walter Roberson 2017년 11월 15일
Hi all,
I have a figure like this which was obtained by numerical solution. I want to use different color for different segments. Can anyone please help?
  댓글 수: 1
KSSV
KSSV 2017년 11월 13일
The figure already have different colors right? What data you have to plot? YOu need to use plot with different colors options. Read about plot.

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 13일
In MATLAB, any one "primitive line object" is restricted to being a single color. If you want multiple colors, then you need to draw multiple lines -- or you need to take a very different approach such as drawing a surface or patch with face colors turned of and edge colors specified; for example see https://www.mathworks.com/matlabcentral/fileexchange/19476-colored-line-or-scatter-plot
  댓글 수: 3
Image Analyst
Image Analyst 2017년 11월 15일
For example, if index1, index2, index3, and index4 are in order:
plot(x(index1:index4), y(index1:index4), 'b-', 'LineWidth', 4);
hold on;
plot(x(index2:index3), y(index2:index3), 'r-', 'LineWidth', 4);
This will plot a blue line with a red portion in the middle.
Walter Roberson
Walter Roberson 2017년 11월 15일
There is no other way. "primitive line objects" can never have multiple colors for one line, so you need to use multiple lines or you need to use a different kind of graphics object.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by