zoom scatter dots inside a figure

11 ビュー (過去 30 日間)
mat
mat 2013 年 7 月 16 日
編集済み: Samayochita 2025 年 2 月 14 日 10:31
hi,
zooming into a figure does not correspondingly enlarge the scatter dots in the figure (for example).
is there an elegant way of doing it?
thanks a lot,
mat
  1 件のコメント
mat
mat 2014 年 1 月 5 日
hi
can anyone help?
thanks a lot !
mat

サインインしてコメントする。

回答 (1 件)

Samayochita
Samayochita 2025 年 2 月 14 日 10:10
編集済み: Samayochita 2025 年 2 月 14 日 10:31
Hi mat,
To make the scatter points appear to zoom proportionally with the figure, you can use SizeData property(https://in.mathworks.com/help/matlab/ref/scatter.html#:~:text=Change%20the%20marker,SizeData%20%3D%20100%3B%0Acolorbar) along with ActionPostCallback.
Below is a code section of how you could achieve this:
s = 100; % A random marker size
figure;
hScatter = scatter(x, y, s, 'filled');
% Adjust marker size when zooming
zoomObj = zoom;
set(zoomObj, 'ActionPostCallback', @(src, evnt) adjustMarkerSize(hScatter));
% zoomObj.ActionPostCallback triggers adjustMarkerSize after zooming.
The “adjustMarkerSize” function has been defined to fetch the axes limits (XLim, YLim) to determine the zoom level and adjust theSizeData property as you zoom into the plot.
function adjustMarkerSize(hScatter)
ax = ancestor(hScatter, 'axes');
xLim = ax.XLim;
yLim = ax.YLim;
% Compute new marker size based on zoom level
scaleFactor = mean([diff(xLim), diff(yLim)]);
hScatter.SizeData = 1000 / scaleFactor; % Adjust size inversely to zoom level
end
Hope this helps!

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by