How to make markers bigger/smaller when zooming in/out on a plot?
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 22 Nov. 2019
Bearbeitet: MathWorks Support Team
am 8 Sep. 2021
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?
Akzeptierte Antwort
MathWorks Support Team
am 8 Sep. 2021
Bearbeitet: MathWorks Support Team
am 8 Sep. 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Exploration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!