What is the easiest way to plot a circle annotation that maintains its shape regardless of figure dimensions?
17 次查看(过去 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1169668/image.png)
And here's what happens if I resize the figure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1169673/image.png)
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 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!