Plot position in uiaxes not precise?

5 次查看(过去 30 天)
Jonas
Jonas 2023-4-24
评论: Jonas 2023-5-8
Dear community,
- Edit below -
I tried to plot a cross on an image placed into a uiaxes in a uifigure and i noticed, that the cross is not exactly at my mouse location. Is this a graphics problem on my side or does it also appear for others? I tried two version, once with the Intersection Point of the Image Button Down Callback and once the CurrentPoint property of the uiaxes callback, both do not result into precise crosses:
here a MWE:
f=uifigure;
ax=uiaxes(f);
im=imagesc(ax,rand(5));
hold(ax,'on');
im.ButtonDownFcn=@(~,event) plot(ax,event.IntersectionPoint(1),event.IntersectionPoint(2),'Color','red','Marker','x','MarkerSize',12);
and here using the current point of the axes:
f=uifigure;
ax=uiaxes(f);
im=imagesc(ax,rand(5));
im.HitTest="off";
hold(ax,'on');
ax.ButtonDownFcn=@(src,~) plot(src,src.CurrentPoint(1,1),src.CurrentPoint(1,2),'Color','red','Marker','x','MarkerSize',12);
unfortunately i can not show a screenshot, since the mouse in not captured using the windows onboard screenshot tools. The plot location can vary in all directions.
EDIT:
I just noticed the reason for this behavior may be due to the attached monitor I use with my laptop or the display scaling. Does somone know some kind of workaround for the issue?
EDIT2:
My setting were 125% scaling on the laptop screen and 100% scaling on the additional monitor. using these settings, the plot location was precise on th elaptio screen, but not on the monitor. If I change the scaling of the monitor also to 125%, the positioning becomes precise.
EDIT3:
finally, this is all about scaling problems in matlab. see workaround in
actually, i dont know if there is also that problem for compiled apps
  2 个评论
chicken vector
chicken vector 2023-4-24
Just a quick comment since you have already figured it out.
This always work, regardless of the monitor settings:
f=uifigure;
ax=uiaxes(f);
im=imagesc(ax,rand(5));
hold(ax,'on');
im.ButtonDownFcn={@makeCross,ax};
function makeCross(~,event,ax)
point = get(ax,'CurrentPoint')
plot(ax,point(1,1),point(1,2),'Color','red','Marker','x','MarkerSize',12);
end
Jonas
Jonas 2023-5-8
thanks for response. the method using CurrentPoint seems to bit slightly better, bit for me it also does not perform perfectly

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by