App Designer Axes Pan and Zoom cause drawing problem
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!