Does anyone know if it is possible to give a different color to select intervals of a curve

1 回表示 (過去 30 日間)
Truman Cassady
Truman Cassady 2018 年 6 月 13 日
回答済み: Walter Roberson 2018 年 6 月 13 日
I am modelling a material property curve and want to have different colors represent different elastic behavior. -Thanks
  1 件のコメント
John D'Errico
John D'Errico 2018 年 6 月 13 日
編集済み: John D'Errico 2018 年 6 月 13 日
The lazy solution is to break the curve into segments, that you then plot separately, each with its own color assigned. Do you want a smoothly interpolated color gradient along the curve?

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2018 年 6 月 13 日
n = 100;
x = linspace(-10,10,n); y = x.^2;
z = zeros(size(x));
col = x; % This is the color, vary with x in this case.
surface([x;x],[y;y],[z;z],[col;col],...
'facecolor','no',...
'edgecolor','interp',...
'linewidth',2);

Walter Roberson
Walter Roberson 2018 年 6 月 13 日
Look in the File Exchange; there are a few contributions for handling colored lines.
There are three basic approaches:
  1. break the range up into segments each with consistent color, and output enough line() objects to draw the whole; this has the simplest representation, easiest to understand the output graphics objects, but is the most expensive to draw; or
  2. use surface() objects (includes mesh objects) to draw colored edges; or
  3. use patch() objects to draw colored edges. This has the greatest flexibility about how the color of the edges is to be determined.
The file contribution has various implementations that include each of the three techniques.

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by