(App Designer) How to link axes of UIAxes components to enable user to zoom all plots together in AppDesigner 2018b?
15 次查看(过去 30 天)
显示 更早的评论
I am building an app where I have three plots in a single tab. What I want to do is showing user the specific zoomed area in the plots synchronized. To do that, I tried to use linkprop/linkaxes function but unfortunately it is not supported with UIAxes.
My software version is 2018b. How do I workaround this issue? What is the logic of using listeners for my purpose?
0 个评论
采纳的回答
Kevin Chng
2018-12-4
Hi Deniz,
As per knowledge, I don't how to do link them simultaneously. However, we may play small trick.
I have attached small sample hereby (.m file, since .mlapp is not accepted here, I copy the code and paste in .m file)
Idea : Enable Zoom for both axes in startup function, then use keypress callback function to reset another axes when one of the axes changes due to zoom
[However, from method above, user have to pressing one of the keyboard button when zooming the plot]
Step 1: Create Variables to store original XLim of both axes
properties (Access = private)
a % Description
b
end
Step 2 : Enable zoom for the both axes in startup function
zoom(app.UIAxes,'on')
zoom(app.UIAxes2,'on')
Step 3: Record the Xlim of axes after plotting them. In my attached, i do it in startup function
plot(app.UIAxes,[0 1],[0 1]);
plot(app.UIAxes2,[0 0.2 1],[0 0.9 1]);
app.a = app.UIAxes.Xlim;
app.b = app.UIAxes2.Xlim;
Step 4 :Use keyPress function to detect the changes of one axes, then it will change the xlimit and ylimit for another axes.
function UIFigureKeyPress(app, event)
key = event.Key;
if app.UIAxes.XLim ~= app.a
app.UIAxes2.XLim = app.UIAxes.XLim;
app.UIAxes2.YLim = app.UIAxes.YLim;
elseif app.UIAxes2.XLim ~=app.b
app.UIAxes.XLim = app.UIAxes2.XLim;
app.UIAxes.YLim = app.UIAxes2.YLim;
end
end
You may try to run my .m script to get the idea, when you wana zoom it and enable another axes to have same x&y limit, you must press one of the button in the keyboard.
I hope my workaround solution help you.
更多回答(2 个)
Weidong Xu
2019-11-30
编辑:Weidong Xu
2019-11-30
Another workaround, which was suggested by app designer's migration report, is to
"Call the axes, polaraxes, or geoaxes function to create the axes first. Create the desired plot, and then call the linkprop function."
For example, you can create app.UIAxes in the StartupFcn by calling
app.UIAxes = axes(app.FigureUI);
(rather than app.UIAxes = uiaxes(app.FigureUI), which was called by app designer constructor by default). Then linkprop will work for app.UIAxes.
0 个评论
Eddy Fry
2022-6-16
I managed to get this working in 2022a by adding linkaxes code to startupFcn as follows:
evStr = 'linkaxes([app.UIAxes_1';
for i = 2:nAxes
evStr = [evStr,',app.UIAxes_',num2str(i)];
end
evStr = [evStr,'],''xy'');'];
eval(evStr);
There is probably a better way than using eval(), but this is OK for me right now as I'm not compiling the code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!