Adding different colorbars to each row of subplots? Removing subplot axes? Decrease subplot spacing?

8 views (last 30 days)
I am having a hardtime figuring out how to do a few things to a subplot. I will list them below:
  1. COLORBAR: When I try to add colorbars to each row of subplots in a 4x5 subplot figure (see image attached), It adds all the colorbars to the lower right corner. Two things wrong with this... 1) i need one colorbar for each row corresponding to that particular color. 2) I would like the colorbar to be outside of the subplot so that each subplot is the same shape. I indicated this on the attached image with the black markings.
  2. AXES: I would like to remove the y axes from each subplot except for the one on the left side (column 1). Similarly, I'd like to remove the x axis from each subplot except for the bottom (row 5).
  3. SPACING: I would like to decrease the spacing in between each subplot.
I included a more simplified version of my code below. Thanks so much in advance.
count = 0;
ax = zeros(4,5);
for i = 1:length(cells)
for k = 1:length(Sess)
count = count+1
ax(i,k) = subplot(4,5,count);
imagesc(CSbyShut); hold on;
set(gca,'XTick',0:150:600);
xticklabels({'-5','0','10','15','20'})
caxis([-5 15])
set(gcf, 'Position', [100, 100, 1500, 800])
xline(150,'-r');xline(450,'-r');
end
end
for t = [1,5,9,13,17]
colormap(ax(t),Map.blackmap);colorbar;
end
for t = [2,6,10,14,18]
colormap(ax(t),Map.bluemap);colorbar;
end
for t = [3,7,11,15,19]
colormap(ax(t),Map.greenmap);colorbar;
end
for t = [4,8,12,16,20]
colormap(ax(t),Map.redmap);colorbar;
end

Accepted Answer

Srivardhan Gadila
Srivardhan Gadila on 27 May 2020
The following code might help you w.r.t the points 1. COLORBAR(Changing the Position (position: [left bottom width height]) property of the colobar) & 2. AXES (Axes Properties - Ticks)
close all
count = 0;
for i = 1:4
for k = 1:5
count = count+1
ax(i,k) = subplot(4,5,count);
% imagesc(CSbyShut);
hold on;
set(gca,'XTick',0:150:600);
xticklabels({'-5','0','10','15','20'})
caxis([-5 15])
set(gcf, 'Position', [100, 100, 1500, 800])
xline(150,'-r');xline(450,'-r');
if i~= 4
set(gca,'XTick',[])
end
if k~=1
set(gca,'YTick',[])
end
end
end
colormap(ax(1,5),'parula');
pos = get(subplot(4,5,5),'Position')
h = colorbar('Position', [pos(1)+pos(3)+0.02 pos(2) pos(3)/10 pos(4)]);
c2 = colormap(ax(2,5),'jet');
pos = get(subplot(4,5,10),'Position')
h = colorbar('Position', [pos(1)+pos(3)+0.02 pos(2) pos(3)/10 pos(4)]);
c3 = colormap(ax(3,5),'gray');
pos = get(subplot(4,5,15),'Position')
h = colorbar('Position', [pos(1)+pos(3)+0.02 pos(2) pos(3)/10 pos(4)]);
c4 = colormap(ax(4,5),'pink');
pos = get(subplot(4,5,20),'Position')
h = colorbar('Position', [pos(1)+pos(3)+0.02 pos(2) pos(3)/10 pos(4)]);
Regarding reducing the space between adjacent subplots you can make use of the resources in the following page: "tight subplot" MathWorks Help Center

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!