MATLAB Answers

how to apply a uniform color gradient to a patch object

21 views (last 30 days)
Ramiro Massol
Ramiro Massol on 20 May 2015
Edited: Star Strider on 20 May 2015
hi I'm trying to show a filled histogram of selected images. The fill" area under the curve will indicate the color assignment determined by a user-specified colormap. I'm using a patch object to create the filled area. The problem I have is that the shading of the patch is not uniform from left to right, i.e. I expected vertical slabs of color but instead the patch shows odd diagonal-like shading that I have no idea how to remove. I I'm not sure what I'm doing wrong. A code that reproduces this behavior is shown below:
x = log10(sort(randi([900 65535],1,256)));
y = log10(randi([1 150000],1,256));
X = [x(1) x x(end)];
Y = [0 y 0];
cmap = colormap(gray(258));
hline = line(x,y,'Color','r','LineStyle','-','LineWidth',2);
hold on
patch('Faces',1:size(X,2),'Vertices',[X' Y'],'FaceVertexCData',cmap,'FaceColor','interp')
hold off
Please help! best Ramiro email:;


Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!