How to make markers bigger/smaller when zooming in/out on a plot?
28 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-11-22
编辑: MathWorks Support Team
2021-9-8
I have a plot with a bunch of data points. When I zoom in, the markers stay the same size relative to the figure window. I understand this is the default behavior, but is there a way to make the markers grow "bigger" when I zoom in, and "smaller" when I zoom out?
采纳的回答
MathWorks Support Team
2021-9-8
编辑:MathWorks Support Team
2021-9-8
The fact that markers do not get "bigger" when you zoom in is, of course, expected, since a point is infinitely small and should have no no extent. The "MarkerSize" is defined in units of "points", which (like "pixels") is measured relative to the screen itself, not the axis.
There are two possible ways to achieve the desired resizing of markers:1) Create a zoom object associated with your figure and add an ActionPostCallback that resizes your markers every time the user zooms in/out:
The zoom callback can be created as follows;
plot(x,y);
h_zoom = zoom;
h_zoom.ActionPostCallback = {@resize_markers, ...} % ... signifies extra input args
I have created a simple example in the attached script ("resize_markers_example.m") that resizes markers based on the changing length of the x-axis.
I begin by plotting a a bunch of data points with an initial marker size of 10 point. Then, I determine the conversion factor between points and x-axis units by dividing the current axis length in points by the axis length in x-axis units. This conversion factor will need to be recalculated each time the user zooms in/out.
With the initial conversion factor, I can determine the marker size in permanent x-axis units. Each time the user zooms in/out, the zoom callback will recalculate the conversion factor and use it to determine the new marker size in units of points.
The limitation to this method is that it is only taking the x-axis into account. So, it is best for the user to zoom in equally with regards to the x- and y-axis.
2) Another way to solve this problem would be to use the "patch" function to plot filled in circles that resemble points, rather than plotting actual points. When you zoom in/out, these filled circles will grow bigger/smaller. To plot many filled circles, see the following MATLAB Answers post:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!