how show weights with different color

7 views (last 30 days)
Hi,
I would like to plot lines with different weights and visualize weights with color. For example,
x = 1:100;
y = rand(50,100);
weight = rand(100,1);
plot(y,x)
x is x-axis coordinate, y is y-axis coordinate and weight is the weights for these 100 lines. I wish to plot these lines with the color proportional to the weight. Could anybody give me an idea on this? Thanks in advance.

Accepted Answer

Adam Danz
Adam Danz on 29 Aug 2019
See comments
h = plot(y,x); % There should be 1 handle per line object
% choose the colormap (eg, jet) and number of levels (eg, 100)
nLevels = 100;
cmat = jet(nLevels);
% Assign each weight to a row of color.
weightNorm = (weight-min(weight))./range(weight); %normalized 0:1
[~,~,crow] = histcounts(weightNorm,linspace(0,1,nLevels));
% assign color
set(h,{'Color'},mat2cell(cmat(crow,:),ones(size(h)),3))

More Answers (0)

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!