Custom color map for plotting matrix values
显示 更早的评论
Here's an example of what I want to do, but instead of a loop for the plot, I want to feed in plot(x,y); instead of plot(x,y(i,:))
% Define vector values
n = 101; N = 30;
x = linspace(0,2,n);
y = ((-N/2:N/2)').*x.^4;
% Plot
figure; hold on;
% Prepare colormap
Color1 = [0,0.5,1];
Color2 = [1,0.5,0];
for i = 1:N
Col = Color1 + (Color2 - Color1)*(i-1)/(N-1);
plot(x,y(i,:),'Color',Col);
end
Where, I want to replace
for i = 1:N
Col = Color1 + (Color2 - Color1)*(i-1)/(N-1);
plot(x,y(i,:),'Color',Col);
end
with
for i = 1:N
Col(i,:) = Color1 + (Color2 - Color1)*(i-1)/(N-1);
end
plot(x,y,'Colors',Col);
with the following plot as the result.

2 个评论
Adam
2017-7-28
What are you actually trying to do? Colourmaps don't apply to line plots whose default colours are controlled by the 'ColorOrder' property of the colourmap.
But your 'Col' variable is just a 3-element vector - i.e. a single colour, so if you just want to set all lines to the one colour then that is trivial, but doesn't count as a colourmap so I assume something is missing from your example?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
