plot the lines with different color
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I have generated a plot using x and y and would like to add color on it based on its value (diameter of line). I have used the https://github.com/vistalab/vistateach/blob/master/cogneuro/tutorial1_timeseries/vals2colormap.m
to convert my range of value to rgb value
x = [0.168149323 0.547990492 0.580721962 0.502272216 0.321295719 0.168149323];
y = [0.565541486 0.530969047 0.570321397 0.878624621 1.069086578 0.565541486];
colorrange=[27.65 22.11 23.11 25.11 26.74 26.94]
rgb=vals2colormap(colorrange, 'jet',[22.11 27.65])
%rgb=[0.5,0,0;0,0,0.515625;0,0.234375,1;0.671875,1,0.3281250;1,0.15625,0;1,0.015625,0]
%rgb is colormap value for different line
for k = 1 : length(rgb)
hold on
% Get new values.
plot(x, y,'-', 'Color', rgb(k,:) ,'LineWidth',2)
end
however, when I plot them out, all the color are the same.

any idea I can make different line to different color based on their specific value?
0 commentaires
Réponse acceptée
Image Analyst
le 6 Juin 2022
Try this:
x = [0.168149323 0.547990492 0.580721962 0.502272216 0.321295719 0.168149323];
y = [0.565541486 0.530969047 0.570321397 0.878624621 1.069086578 0.565541486];
numColors = numel(x)
cmap = jet(numColors);
colorrange=[27.65 22.11 23.11 25.11 26.74 26.94]
cMapIndexes = round(rescale(colorrange, 1, numColors))
for k = 2 : length(x)
hold on
% Get new values.
thisColor = cmap(cMapIndexes(k),:);
fprintf('Plotting line from point %d to point %d as [%.2f, %.2f, %.2f].\n', ...
k-1, k, thisColor(1), thisColor(2), thisColor(3))
plot([x(k-1), x(k)], [y(k-1), y(k)], '-', 'Color', thisColor ,'LineWidth', 5)
end
grid on;
xlabel('x');
ylabel('y')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
