Define properties of colorbar
Ältere Kommentare anzeigen
Hello, I am trying to configure a colorbar but there are two information that I don't know how to do.
This is the image of my plot

In addition, I am adding the code below:
function [ ] = Figure1(TT,aux,x,y)
set(gcf,'Color',[1 1 1]);
h=colorbar('SouthOutside');
set(h, 'Position', [.05 .15 .9 .05]);
load('MyColormap.mat')
if aux == 1
subplot('Position',[.0 .25 .20 .20]);
elseif aux == 2
subplot('Position',[.25 .25 .20 .20]);
elseif aux == 3
subplot('Position',[.5 .25 .20 .20]);
else
subplot('Position',[.75 .25 .20 .20]);
end
shading flat
pcolor(x,y,TT')
colormap(mymap)
caxis([275 320])
shading interp
view(2)
axis square
set(gca,'Visible','off')
end
What I need:
- Define (reduce) the space between subplot(1,4,1) e subplot(1,4,2) .....
- Add a title on my horizontal colorbar.
PS: I have already read many links, but I couldn't find a concrete information!
Cheers
12 Kommentare
jonas
am 1 Jul. 2018
Just change the first values in the position vector to reduce the space?
Title is added by
h.Label.String='title'
As described in the doc
yogan sganzerla
am 1 Jul. 2018
Walter Roberson
am 1 Jul. 2018
Bearbeitet: Walter Roberson
am 1 Jul. 2018
The 'Position' option is followed by [lower_left_x, lower_left_y, width, height] . If you want your axes to be closer together, you can modify the coordinates to put them closer together.
However, you need to be careful with subplot: if it thinks there is an overlap with an existing axes, it will delete the axisting axes.
It might make more sense to create four axes ahead of time using axes() with appropriate position, and then to fetch the handle for the appropriate one according to the value of aux.
yogan sganzerla
am 1 Jul. 2018
Walter Roberson
am 2 Jul. 2018
function [ ] = Figure1(TT,aux,x,y)
persistent known_axes mymap
if isempty(known_axes) || ~all(ishandle(known_axes))
delete( findobj(gcf, '-regexp', 'tag', '^bax_\d+') );
basepos = 0.15; %for example
axwidth = 0.25;
for K = 1 : 4
known_axes(K) = axes('InnerPosition', [basepos + (K-1)*axwidth, 0.25, axwidth, 0.20], 'Tag', sprintf('bax_%d', K)); %note use of InnerPosition
end
datastruct = load('MyColormap.mat');
mymap = datastruct.mymap;
end
cax = known_axes(aux);
set(gcf, 'Color',[1 1 1]);
h = colorbar(cax, 'SouthOutside');
set(h, 'Position', [.05 .15 .9 .05]);
shading(cax, 'flat');
pcolor(cax, x, y, TT');
colormap(cax, mymap);
caxis(cax, [275 320]);
shading(cax, 'interp');
view(cax, 2);
axis(cax, 'square');
set(cax,'Visible','off')
end
Note: this code is not correct for the case where you are using the function for two different figures.
yogan sganzerla
am 2 Jul. 2018
Walter Roberson
am 2 Jul. 2018
You can change axwidth and you can change the equation
basepos + (K-1)*axwidth
For example you could define
overlap = 0.02;
and use
basepos + (K-1)*(axwidth - overlap)
jonas
am 2 Jul. 2018
yogan sganzerla
am 2 Jul. 2018
Try typing (in matlab)
help tight_subplot
The output is an array of handles, with a size of Nw*Nh (i.e. number of axes). Each handle is one axes.
When you want to plot in a certain axes, you need to make that axes the current axes. Let's say your array of handles is called ha (output from the function) and you want to plot in the axes located in the upper left corner of your grid. Then you type:
axes(ha(1))
plot(...
Always check the doc when using a new function, it's usually very comprehensive and filled with examples. If you use functions from FileExchange, then type help function in matlab.
yogan sganzerla
am 5 Jul. 2018
jonas
am 5 Jul. 2018
I don't know what it means to integrate subplot(1,4,1) with ha(1). See my answer below.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu White finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





