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!