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

I used imagesc

MatLab to plot the acoustic field. Now I want to overlay a semi-transparent filled rectangle at a specific location in the image. Ideally, I would like 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 and 0.5 is the transparency. It can be done?

+3


source to share


1 answer


You can use rectangle

to create a rectangle object and then use the color specified as RGBA to enable transparency

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

      



Alternatively, you can just use patch

object

p = patch('vertices', [100, 100; 100, 200; 200, 200; 200 100], ...
          'faces', [1, 2, 3, 4], ...
          'FaceColor', 'b', ...
          'FaceAlpha', 0.5)

      

+3


source







All Articles