Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlaying a semi-transparent rectangle on an plot created with imagesc?

I have used imagesc in MatLab to plot an acoustic field. I now want to overlay a semi-transparent filled in rectangle at a certain location on the image. Ideally I'd like to be able to do something like the following:

imagesc(g,g,field);
hold on
plotRectangle([100,100,200,200], 'b', 0.5)
hold off

where b is the color of the rectangle 0.5 is the transparency. Can this be done?

like image 678
sonicboom Avatar asked Mar 10 '23 08:03

sonicboom


1 Answers

You can use rectangle to create a rectangle object and then use a color specified as RGBA to include transparency

rectangle('Position', [100 100 200 200], 'FaceColor', [0 0 1 0.5])

Alternately, you can just use a patch object

p = patch('vertices', [100, 100; 100, 200; 200, 200; 200 100], ...
          'faces', [1, 2, 3, 4], ...
          'FaceColor', 'b', ...
          'FaceAlpha', 0.5)
like image 119
Suever Avatar answered Apr 07 '23 08:04

Suever