- Programmatically Control the Axes Limits: Add a callback function to control the horizontal zoom.
- Show/Hide Toolbar Based on Mouse Movement: Adjust the toolbar visibility based on the mouse position.
Graph adjust controls play peekaboo
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
My App Designer created app has a graph on it. My users want to adjust the horizontal axis (zoom in horizontally only)
I found where I can set that with a right click but the control things in the upper left corner are disappearing when ever the mouse approaches. Can't get there to grab one fast enough most of the time. Make them disappear when the mouse is NOT there and appear when it is please.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1732803/image.jpeg)
0 Commenti
Risposte (1)
Ruchika Parag
il 14 Lug 2024
Hi Alessandro, for users to be able to adjust the horizontal axis in your app, you can programmatically control the appearance and behavior of the axes toolbar. You can try the following:
Please try the following steps for the same:
1. Add UI Controls for Horizontal Zoom
Add buttons or a slider in your app to control the horizontal zoom. For example, add two buttons "Zoom In" and "Zoom Out".
2. Add Callback Functions for Zoom Controls
Add callback functions for the zoom controls to adjust the XLim property of the axes.
% Zoom In Button Callback
function ZoomInButtonPushed(app, event)
ax = app.UIAxes; % Replace with your actual axes name
xlim = ax.XLim;
center = mean(xlim);
range = diff(xlim) / 2;
newXLim = [center - range/2, center + range/2];
ax.XLim = newXLim;
end
% Zoom Out Button Callback
function ZoomOutButtonPushed(app, event)
ax = app.UIAxes; % Replace with your actual axes name
xlim = ax.XLim;
center = mean(xlim);
range = diff(xlim) * 2;
newXLim = [center - range/2, center + range/2];
ax.XLim = newXLim;
end
3. Control Toolbar Visibility Based on Mouse Movement
You can use the 'WindowButtonMotionFcn' property of the figure to detect mouse movement and show/hide the toolbar accordingly.
% In the startup function of your app
function startupFcn(app)
app.UIFigure.WindowButtonMotionFcn = @(src, event) detectMouseMovement(app);
end
% Function to detect mouse movement
function detectMouseMovement(app)
ax = app.UIAxes; % Replace with your actual axes name
currentPoint = app.UIFigure.CurrentPoint;
axPosition = ax.Position;
figPosition = app.UIFigure.Position;
% Calculate the position of the axes in figure coordinates
axLeft = figPosition(1) + axPosition(1) * figPosition(3);
axBottom = figPosition(2) + axPosition(2) * figPosition(4);
axWidth = axPosition(3) * figPosition(3);
axHeight = axPosition(4) * figPosition(4);
% Check if the mouse is over the axes
if currentPoint(1) >= axLeft && currentPoint(1) <= (axLeft + axWidth) && ...
currentPoint(2) >= axBottom && currentPoint(2) <= (axBottom + axHeight)
% Show toolbar
ax.Toolbar.Visible = 'on';
else
% Hide toolbar
ax.Toolbar.Visible = 'off';
end
end
By following these steps, you should be able to provide your users with the ability to zoom in horizontally and control the visibility of the axes toolbar based on mouse movement. Hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Object Properties in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!