Chart loses bottom and right upon resize
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
One of the users of our compiled MATLAB program has an issue when he resizes the main window. As the window is made larger, a chart inside the window slowly loses its bottom and right side. This does not happen with any of the similar charts in pop-up windows (each of which is created from the main window by pressing various buttons). It also does not happen if the "Scale and layout" in Windows display settings is set to 150%.
Good chart (before resize or with windows scaling 150%)
Bad chart (after resize or with windows scaling 125%)
I am a MATLAB newbie but unfortunately am required to maintain this program, so I'm pretty clueless. Please excuse any obvious ignorance on my part.
I found the following issue that apparently is a Windows 10 problem but am not sure it is the same as what I am seeing:
Here is the relevant code for the main window:
scrsz1 = get(0,'ScreenSize');
xmin=scrsz1(1)+ .01*scrsz1(3);
ymin=scrsz1(2)+ .05*scrsz1(4);
wi=.98*scrsz1(3);hi=.87*scrsz1(4);
hfig=openfig('mainWindow.fig','reuse');
set(hfig,'units','pixels')
set(hfig,'position',[xmin ymin wi hi])
set(hfig,'units','normalized')
Here is the relevant code for one of the pop-up windows:
axestagh='pictureaxis';
ha=findobj('tag',axestagh);
xlim0=get(ha,'Xlim');
ylim0=get(ha,'Ylim');
xtick0=get(ha,'XTick');
nhf=figure;
nha=copyobj(ha,nhf);
np=get(nha(1),'position');
set(nha,'position',[.12 .12 .8 .8],'tag','sep1');
set(nha,'Xlim',xlim0,'XTick',xtick0);
If the code difference does not explain this, could there be something in the differences between the .fig files that is causing it? I appreciate any help (or even an explanation) you can give.
0 Commenti
Risposte (1)
Shrey Tripathi
il 14 Giu 2023
Modificato: Shrey Tripathi
il 14 Giu 2023
The problem may be linked with the resizing of the main window. The provided code snippets do not have explicit codes to resize the chart's axes inside the main window when the window is resized, which could be the reason behind the issue.
If the chart inside the main window was created via MATLAB's GUI, then you can set the axes' unit property to "normalized". By doing so, you can utilize the position property to ensure that the chart is resized correctly upon window resizing. An example code snippet that could be used:
% Obtain chart axes handle
axesHandle = handles.chart_axes; % Replace 'chart_axes' with the correct tag for the axes object.
% Configure axes units to 'normalized'
set(axesHandle, 'Units', 'normalized');
% Set position of the axes: [left bottom width height]
set(axesHandle, 'Position', [0.1 0.1 0.8 0.8]);
% Define XLim and YLim axes properties to make sure the chart remains within the axes.
You can also use other means, such as findobj to get the handle to the axes object and subsequently set the axes properties.
As for the distinctions between the .fig files, it is difficult to determine without further information. It is plausible that the axes properties vary between the main window chart and the pop-up window charts, which could be the problem. You can analyze and compare the axes properties of both charts to detect any differences.
1 Commento
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks 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!