- Before plotting the histogram, explicitly set the current axes using the axes() function to ensure that the plots and annotations are directed to the correct subplot.Directly call the histogram function to plot the data on the specified axes.
- Use the title() and text() functions to add titles and annotations to the plots. Construct annotation strings using strcat() to include statistical information.
- Ensure that the plots and annotations are not inadvertently cleared by setting the axes context appropriately.
How to update titles and text annotations of subplots located on the same uitab?
4 次查看(过去 30 天)
显示 更早的评论
% TAB 1
S.tabH(1) = uitab(S.histoTab, 'Title', 'Error X');
S.P1_histo{1} = subplot(2,2,[1 3], 'Parent', S.tabH(1));
s2.tab1sp1 = hggroup;
S.P1_histo{2} = subplot(2,2,[2 4], 'Parent', S.tabH(1));
s2.tab1sp2 = hggroup;
% TAB 2
S.tabH(2) = uitab(S.histoTab, 'Title', 'Error Y');
S.P2_histo{1} = subplot(2,2,[1 3], 'Parent', S.tabH(2));
title('On Fly');
s2.tab2sp1 = hggroup;
S.P2_histo{2} = subplot(2,2,[2,4], 'Parent', S.tabH(2));
title('Static');
s2.tab2sp2 = hggroup;
%%In the Callback Function
handles = guidata(source);
currentTab = find(source.SelectedTab == S.tabH);
switch currentTab
case 1
if ~isempty(handles.R_Site_X_Static_NM_DRF)
histogram(handles.R_Site_X_Static_NM_DRF, 'parent',s2.tab1sp2);
ThreeSig_X_S = 3 * std(handles.R_Site_X_Static_NM_DRF);
stringH1 = strcat({'Static, '},{'3sig: '}, {num2str(ThreeSig_X_S)});
title(S.P1_histo{1}, 'Static');
text(S.P1_histo{1},0, 200, stringH1);
end
if ~isempty(handles.R_Site_X_OnFly_NM_DRF)
histogram(handles.R_Site_X_OnFly_NM_DRF, 'parent', s2.tab1sp1);
ThreeSig_X_OF = round(3 * std(handles.R_Site_X_OnFly_NM_DRF),3);
stringH2 = strcat({'3sig: '}, {num2str(ThreeSig_X_OF)});
title(S.P1_histo{2}, 'On Fly');
text(S.P1_histo{2},0.2, 130, stringH2, 'FontWeight', 'Bold');
end
case 2
...
I am getting the title and text annotation only for the second subplot of tab 1. When debugging the code line by line, I get the title and text for the first subplot too, but it later disappears.
0 个评论
回答(1 个)
Naga
2024-10-23
The issue you're facing with the title and text annotations disappearing could be related to the use of hggroup as the parent for your histograms. When you update a plot with a new plot command (like histogram), it usually clears the axes unless you specify otherwise. Here are a few suggestions to fix this issue:
This approach ensures that each subplot retains its title and annotations after plotting. Please find the updated code:
% TAB 1
S.tabH(1) = uitab(S.histoTab, 'Title', 'Error X');
S.P1_histo{1} = subplot(2,2,[1 3], 'Parent', S.tabH(1));
S.P1_histo{2} = subplot(2,2,[2 4], 'Parent', S.tabH(1));
% TAB 2
S.tabH(2) = uitab(S.histoTab, 'Title', 'Error Y');
S.P2_histo{1} = subplot(2,2,[1 3], 'Parent', S.tabH(2));
title(S.P2_histo{1}, 'On Fly');
S.P2_histo{2} = subplot(2,2,[2 4], 'Parent', S.tabH(2));
title(S.P2_histo{2}, 'Static');
% Callback Function
handles = guidata(source);
currentTab = find(source.SelectedTab == S.tabH);
switch currentTab
case 1
if ~isempty(handles.R_Site_X_Static_NM_DRF)
axes(S.P1_histo{1});
histogram(handles.R_Site_X_Static_NM_DRF);
title('Static');
text(0, 200, strcat('Static, 3sig: ', num2str(3 * std(handles.R_Site_X_Static_NM_DRF))));
end
if ~isempty(handles.R_Site_X_OnFly_NM_DRF)
axes(S.P1_histo{2});
histogram(handles.R_Site_X_OnFly_NM_DRF);
title('On Fly');
text(0.2, 130, strcat('3sig: ', num2str(round(3 * std(handles.R_Site_X_OnFly_NM_DRF), 3))), 'FontWeight', 'Bold');
end
case 2
% Additional code for case 2
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!