How to make widths of all subplot and colorbars same?
조회 수: 24 (최근 30일)
이전 댓글 표시
Following is my figure code. However, the size of subplots and colorbars are not same. How can I edit the following code to make all the subplots colorbars of same width. With following figure size, the x labels are appearing half below the figure boundary Can I also shift plots a little bit up?
figure,subplot(131); imagesc([3:0.01:11], time, Prob_ip0); hold on;
plot(ip0_m,time,'k','linewidth', 1.2); xlabel('I_P (km s^-1. kg m-3)');
axis([3 11 2000 2200]); set(gca,'ytick',[2000:40:2200]);
set(gca,'xtick',[3:4:11]); set(gca,'FontSize',11); grid on;
ylabel('Time (sec)'); colorbar; caxis([0 0.0061]);
subplot(132); imagesc([0.4:0.01:7], time, Prob_is0); hold on;
plot(is0_m,time,'k','linewidth', 1.2); xlabel('I_S (km s^-1. kg m-3');
axis([0.4 7 2000 2200]); set(gca,'ytick',[]); % set(gca,'ytick',[2000:40:2200]);
set(gca,'xtick',[0.4:3.5:7]); set(gca,'FontSize',11); grid on;
ylabel('Time (sec.)'); ylabel([]); colorbar; caxis([0 0.0076]);
subplot(133); imagesc([2.000:0.0010:2.600], time, Prob_rho0); hold on;
plot(rho0_m,time,'k','linewidth', 1.2); set(gca,'FontSize',11);
ylabel('Time (sec)'); ylabel([]); set(gca,'ytick',[]); %set(gca,'ytick',[2000:40:2200]);
xlabel('Rho (kg/m^3)'); set(gca,'xtick',[2.000:0.3:2.600]); grid on;
colorbar; colormap(flipud(jet)); caxis([0 0.0082]);
set(gcf, 'position', [500 285 800 410]);
댓글 수: 5
Matt J
2024년 2월 10일
The more usual thing to do in this forum would be for you to run it for us, and explicitly demonstrate the problem.
채택된 답변
Austin M. Weber
2024년 2월 10일
Below is the answer that I provided them for setting the width of all the plots to be the same. You can write a local function that takes the axes handle for a subplot and set the width of the axes:
figure
s1 = subplot(7,1,1);
plot(rand(10),rand(10),'-');
s2 = subplot(7,1,2);
plot(rand(10),rand(10),'-');
s3 = subplot(7,1,3);
plot(rand(10),rand(10),'-');
colorbar
s4 = subplot(7,1,4);
plot(rand(10),rand(10),'-');
colorbar
s5 = subplot(7,1,5);
plot(rand(10),rand(10),'-');
colorbar
s6 = subplot(7,1,6);
plot(rand(10),rand(10),'-');
s7 = subplot(7,1,7);
plot(rand(10),rand(10),'-');
splots = [s1 s2 s3 s4 s5 s6 s7];
for n = 1:length(splots)
position_plot(splots(n))
end
function position_plot(ax)
set(ax,'Units','normalized');
set(ax,'Position',[ax.Position(1), ax.Position(2), 0.4, ax.Position(4)]); % You can change 0.4 (the width) to meet your needs
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!