Hi Marius,
Based on my understanding, you would like to generate a legend in the top-right corner of the plot.
Upon reviewing the provided code, it is evident that the legend's “Units” and “Position” are set to "normalized" and "[0 0 0.5 0.5]" respectively. This implies that the position and size of the legend tile are specified in normalized units, where the entire plot dimensions are represented as 1 in both the x and y directions. The first two elements of the position array indicate the position of the bottom-left corner of the legend tile, while the next two elements denote the width and height of the legend tile. By setting the height and width to 0.5, the size of the legend tile becomes 0.5 times that of the entire plot, resulting in an excessively large legend tile.
One example of keeping the legend at top right corner using “Position” property is given below:
lgd.Position = [0.8 0.8 0.1 0.1];
Please refer to below Mathworks Documentation for more details:
- Legend Properties: https://www.mathworks.com/help/matlab/ref/matlab.graphics.illustration.legend-properties.html#:~:text=Position%20%E2%80%94%20Custom%20location%20and%20size
I hope this helps.
Regards
Binaya