Borrar filtros
Borrar filtros

Graph adjust controls play peekaboo

57 visualizaciones (últimos 30 días)
Alessandro Livi
Alessandro Livi el 11 de Jul. de 2024 a las 21:11
Respondida: Ruchika Parag el 14 de Jul. de 2024 a las 15:30
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.

Respuestas (1)

Ruchika Parag
Ruchika Parag el 14 de Jul. de 2024 a las 15:30
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:
  1. Programmatically Control the Axes Limits: Add a callback function to control the horizontal zoom.
  2. Show/Hide Toolbar Based on Mouse Movement: Adjust the toolbar visibility based on the mouse position.
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!

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by