Coloring Rectangles to Specific Value's Colormap
显示 更早的评论
Hello, all. I am currently trying to create a figure in which I am drawing multiple rectangles on a graph, and then trying to shade them to a certain colormap that is related to a tertiary value. I can't really figure out how to do this via examples online, and I would appreciate some assistance.
My question can be simplified: if I have a nx1 array between 0 and some arbitrary max, how would I determine the color of each element assuming I have the jet colormap set from 0 to the same arbitrary max?
Here is the rectangle code that I am working with:
rectanglesWithValue = [1 1 30; 1 2 60; 1 3 20; 2 1 -1; 2 2 0; 2 3 80; 3 1 50; 3 2 40; 3 3 -1];
xMin = 0;
xMax = 3;
yMin = 0;
yMax = 3;
numRectanglesInX = 3;
numRectanglesInY = 3;
rectWidth = (xMax - xMin)/numRectanglesInX;
rectHeight = (yMax - yMin)/numRectanglesInY;
figure;
axis([xMin xMax yMin yMax])
for i1 = 1:length(rectanglesWithValue(:,1))
%%%IF THE THIRD VALUE OF THE RECTANGLE IS EQUAL TO -1, FILL IT IN BLACK
if rectanglesWithValue(i1,3) == -1
colouring = 'black';
else
%%%IF THE THIRD VALUE OF A RECTANGLE IS BETWEEN min AND max
%%%OF (rectanglesWithValue(:,3)) SET IT TO THE COOL COLORMAP
elementToLinkToColorMap = rectanglesWithValue(i1,3)
%%%This is the code I can't determine
colouring = ??? link elementToLinkToColorMap to the cool color map
%%%This is the code I can't determine
end
rectangle('Position',[rectanglesWithValue(i1,1)-rectWidth/2 rectanglesWithValue(i1,2)-rectHeight/2 rectWidth rectHeight],'FaceColor',colouring);
end
Thanks!
采纳的回答
更多回答(1 个)
simone martinelli
2016-9-28
编辑:simone martinelli
2016-9-28
0 个投票
Have you try to use ''patch'' command? In the help of ''patch'' you can also find how to choose colour or shade your shape.
类别
在 帮助中心 和 File Exchange 中查找有关 Color and Styling 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!