What is the easiest way to plot a circle annotation that maintains its shape regardless of figure dimensions?

6 次查看(过去 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 个评论
Matthew McMahon
Matthew McMahon 2022-10-26
编辑:Matthew McMahon 2022-10-26
Relative to the figure. (Question edited to clarify this.) The size of the circles would preferably not be in terms of the data space of the axes.

请先登录,再进行评论。

回答(1 个)

Steve Eddins
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.

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by