Define colormap according to certain variable.
이전 댓글 표시
Hey!
I have hundreds of 2D-curves in one plot. Curves are produced by function where is a random variable. Now I would like to specify that the curves are displayed with different colors with respect to the value of a used random variable.
What is the proper way to manage this?
답변 (2개)
Hekseli
2013년 10월 24일
댓글 수: 3
AMAR P
2018년 10월 4일
Thanks
Derrick Gao
2019년 8월 8일
it does not work. What is Color ??
Walter Roberson
2019년 8월 8일
The only reference to Color there is in the set(ph) call. ph is the result of the plot() call, so ph will be a graphics handle to a lineseries object, and the set() call will be setting the line color of the lineseries object.
Jonathan LeSage
2013년 10월 23일
You can define a colormap using the hsv function and then define the color of each line according to the random variable that you mention. If you have a vector of the random variables prior to plotting, you can group them via histc and then use the different bin counts to determine which color to assign each line.
If your random numbers are already integers, the problem becomes fairly straightforward. Here is some example code demonstrating the general procedure you might want to try!
% Generate arbitrary random variables
numRandom = 10;
rangeInts = [1 5];
randomVariables = randi(rangeInts,numRandom,1);
% Generate 5 hue-saturation-value color map for your data
% Each row of 'colorVec' defines a different RGB color for you lines
colorVec = hsv(numRandom);
% Define Arbitrary Function for Plotting
xVec = 0:0.1:10;
hold on;
for i = 1:numRandom,
% Arbitrary function which relies on the random variable
yVec = randomVariables(i)*xVec + randn(1,numel(xVec));
% Plot line with color selected by random number
plot(xVec,yVec,'Color',colorVec(randomVariables(i),:))
end
hold off;
Hope this helps you to get started!
카테고리
도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!