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

1

5

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?

Beatnik answered 14/4, 2017 at 11:37 Comment(0)
U
11

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)
Urfa answered 14/4, 2017 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.