App Designer Axes Pan and Zoom cause drawing problem

조회 수: 3 (최근 30일)
smarthu
smarthu 2022년 5월 24일
답변: prabhat kumar sharma 2024년 1월 17일
When using the toolbar tools to pan and zoom in App Designer's Axes figure, sometimes it will cause the axes to be drawn incorrectly, as shown in the following images. The axis is drawn at the wrong place, or the ticks are off the axis. But the saved images are always right, without any problem, which means the displayed image is different from the saved one.

답변 (1개)

prabhat kumar sharma
prabhat kumar sharma 2024년 1월 17일
Hi Smarthu,
I understand that you are facing issue with the distorted axes on zooming the axes figure. The reason to likely this happen could be interactive features like zooming and panning can cause custom-drawn elements like axes lines to be displayed incorrectly. This usually happens because the custom elements do not automatically update their position when the axes limits change. so to deal with the issue you can add listeners to the axes that trigger a redraw of the custom elements whenever the axes limits are changed by panning or zooming.
In the startup function of you app:
addlistener(app.UIAxes, 'XLim', 'PostSet', @(src, event)redrawAxes(app));
addlistener(app.UIAxes, 'YLim', 'PostSet', @(src, event)redrawAxes(app));
Add a public function:
function redrawAxes(app)
% Clear the axes and hold it
cla(app.UIAxes);
hold(app.UIAxes, 'on');
% Get the current limits of the axes
xlims = app.UIAxes.XLim;
ylims = app.UIAxes.YLim;
% Redraw the custom axes lines
plot(app.UIAxes, xlims, [0, 0], 'k', 'LineWidth', 2); % x-axis
plot(app.UIAxes, [0, 0], ylims, 'k', 'LineWidth', 2); % y-axis
% Redraw the intersecting lines at 45 and -45 degrees
plot(app.UIAxes, xlims, xlims, 'b', 'LineWidth', 2); % 45 degrees line
plot(app.UIAxes, xlims, -xlims, 'r', 'LineWidth', 2); % -45 degrees line
% Restore the grid
grid(app.UIAxes, 'on');
% Ensure the 'hold' state is off
hold(app.UIAxes, 'off');
end
when you save a figure to a file, it captures the figure's content as it is defined in the MATLAB graphics system, not necessarily as it appears on the screen. This is because the rendering process for displaying a figure on the screen can differ from the rendering process used to save a figure to a file. Rendering process depends on the resolution, renderer, Figure properties etc.
I hope it helps.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by