What is the easiest way to plot a circle annotation that maintains its shape regardless of figure dimensions?
조회 수: 20 (최근 30일)
이전 댓글 표시
I am trying to annotate a bubblechart (R2022b) that is on a semilogy scale. I have a color scheme for the bubbles, and I am trying to create a custom legend showing what the color scheme means. I am having difficulty finding a convenient way to plot a circle and simply place it at a desired location relative to the figure. If I use "rectangle" or annotation("ellipse"), the shape changes if I change the figure dimensions, and I also have to back the numbers out of the axis units. Ideally I would be able to just specify the position using relative width and height values (relative to the figure, 0 to 1) and specify the size with a number of points (or, say, a fraction of the figure width). Am I missing something obvious?
EXAMPLE: Here's the result if I use the annotation command, where I've tweaked the ellipse size to match these particular figure dimensions: (the non-transparent green circle is added by this code)
annotation(gcf,'ellipse',[0.6 0.7 0.04 0.07],'FaceColor',[0 1 0],'LineStyle','none');
And here's what happens if I resize the figure:
I would like to have the green circle stay circular upon resizing the figure.
댓글 수: 4
답변 (1개)
Steve Eddins
2022년 10월 26일
You can position a circle with the center specified in axes data space by plotting a single point using a circle marker. You can then set MarkerSize, MarkerEdgeColor, and MarkerFaceColor as desired. The size and shape of the circle marker will not change when you resize the figure.
plot(0.5,0.5,Marker = "o",MarkerSize = 20,...
MarkerEdgeColor = [0 1 0], MarkerFaceColor = [0 1 0])
This isn't exactly what you asked for because the circle's center is positioned in axes data space, instead of relative to the figure. I don't have a suggestion for that.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!