我一直在尝试在指南中的等高线图旁边输入一个颜色条,但没有成功。
axes(handles.firstcontouraxes);
contourf(Y,X,z1)
title('First population');
set(gca,'YDir',yinverse,'XDir',xinverse,'clim',[cmin cmax]);
colorbar
颜色栏出现在最右上角,我希望它出现在空的第三个轴框的位置:
当我尝试通过以下方式手动设置其位置时:
pos = get(gca,'position');
colorbar('location','manual','position',[pos(1)+pos(3)+.11 pos(2) .13 pos(4)]);
颜色条出现在面板后面,可以在此图像的底部部分看到:
当我试图把它带到前面时:
HC = get(gcf,'children'); % get the children handles
Hcol = findobj(HC,'tag','Colorbar');%find the colorbar handle
Jcol = find(HC==Hcol);% find its position in the list
HC(Jcol)=[];% delete it from list
HC = [Hcol;HC];% add it to the list top
set(gcf,'children',HC)% set the children in the new order
什么都没发生。
该程序使用如下标签代码:
有 6 个面板:tab1Panel、...、tab6Panel 和 6 个文本框:tab1text、...、tab6text
%% Tabs Code
% Settings
TabFontSize = 10;
TabNames = {'Gaussian','Tilt','Line scan','Area scan','Rename','Macros'};
FigWidth = 0.265;
% Tabs Execution
handles = TabsFun(handles,TabFontSize,TabNames);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ImpFitTwoFour7s3 wait for user response (see UIRESUME)
% uiwait(handles.MoFit_1_11);
% --- TabsFun creates axes and text objects for tabs
function handles = TabsFun(handles,TabFontSize,TabNames)
% Set the colors indicating a selected/unselected tab
handles.selectedTabColor=get(handles.tab1Panel,'BackgroundColor');
handles.unselectedTabColor=handles.selectedTabColor-0.1;
% Create Tabs
TabsNumber = length(TabNames);
handles.TabsNumber = TabsNumber;
TabColor = handles.selectedTabColor;
for i = 1:TabsNumber
n = num2str(i);
% Get text objects position
set(handles.(['tab',n,'text']),'Units','normalized')
pos=get(handles.(['tab',n,'text']),'Position');
% Create axes with callback function
handles.(['a',n]) = axes('Units','normalized',...
'Box','on',...
'XTick',[],...
'YTick',[],...
'Color',TabColor,...
'Position',[pos(1) pos(2) pos(3) pos(4)+0.01],...
'Tag',n,...
'ButtonDownFcn',[mfilename,'(''ClickOnTab'',gcbo,[],guidata(gcbo))']);
% Create text with callback function
handles.(['t',n]) = text('String',TabNames{i},...
'Units','normalized',...
'Position',[pos(3),pos(2)/2+pos(4)],...
'HorizontalAlignment','left',...
'VerticalAlignment','middle',...
'Margin',0.001,...
'FontSize',TabFontSize,...
'Backgroundcolor',TabColor,...
'Tag',n,...
'ButtonDownFcn',[mfilename,'(''ClickOnTab'',gcbo,[],guidata(gcbo))']);
TabColor = handles.unselectedTabColor;
end
% Manage panels (place them in the correct position and manage visibilities)
set(handles.tab1Panel,'Units','normalized')
pan1pos=get(handles.tab1Panel,'Position');
set(handles.tab1text,'Visible','off')
for i = 2:TabsNumber
n = num2str(i);
set(handles.(['tab',n,'Panel']),'Units','normalized')
set(handles.(['tab',n,'Panel']),'Position',pan1pos)
set(handles.(['tab',n,'Panel']),'Visible','off')
set(handles.(['tab',n,'text']),'Visible','off')
end
% --- Callback function for clicking on tab
function ClickOnTab(hObject,~,handles)
m = str2double(get(hObject,'Tag'));
for i = 1:handles.TabsNumber;
n = num2str(i);
if i == m
set(handles.(['a',n]),'Color',handles.selectedTabColor)
set(handles.(['t',n]),'BackgroundColor',handles.selectedTabColor)
set(handles.(['tab',n,'Panel']),'Visible','on')
else
set(handles.(['a',n]),'Color',handles.unselectedTabColor)
set(handles.(['t',n]),'BackgroundColor',handles.unselectedTabColor)
set(handles.(['tab',n,'Panel']),'Visible','off')
end
end
function varargout = MoFit_1_11_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
我遇到了许多答案,但它们没有意义或 在此处、此处和此处不起作用。
这是一个更新:
当我将轴放在面板外时,我可以看到颜色条
但是,一旦我将轴放在面板内,颜色条就会消失