3

I have been trying for a while to input a colorbar beside my contour maps in guide with no luck.

axes(handles.firstcontouraxes);
contourf(Y,X,z1)
title('First population');
set(gca,'YDir',yinverse,'XDir',xinverse,'clim',[cmin cmax]);
colorbar

The Colorbar appears on the far top right corner instead, I would like it to appear in the place of the empty third axes box:

a busy cat

When I try to set its position manually through:

pos = get(gca,'position');
colorbar('location','manual','position',[pos(1)+pos(3)+.11 pos(2) .13 pos(4)]);

The colorbar appears behind the panel and can be seen partially at the bottom of this image:

a busy cat

When I try to bring it to front through:

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

Nothing happens.

The program uses a tab code as follows:

With 6 panels: tab1Panel,..., tab6Panel and 6 text boxes: 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;

Here is a screenshot of the GUIDE: hello

I came across a number of answers but they don't make sense or don't work here,here, and here.

Here is an update:

When I place the axes outside the panel I can see the colorbar

hti

But as soon as I place the axes inside the panel the colorbar disappears

hi

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mosawi
  • 197
  • 2
  • 16

0 Answers0