How to put separate titles above multiple pcolor subplots

조회 수: 6 (최근 30일)
Hi all,
I have a figure of two subplots with pcolor-images. Now I want a separate title above each subplots, but somehow this doesn't work. I don't get an error, but the titles don't show. Anyone an idea how to fix this? Here is my code:
% Plot final modulus image comparison
fig = figure;
set(gcf, 'Position', [50, 100, 1200, 400])
fig_filename = 'final_modulus_map';
ax_min = min([ref_model.mod_img(:); opt_model_k.mod_img(:)]);
ax_max = max([ref_model.mod_img(:); opt_model_k.mod_img(:)]);
subplot(1,2,1);
h=pcolor(ref_model.mod_img);
colormap(hot)
set(h, 'EdgeColor', 'none');
set(gca,'visible','off');
c = colorbar;
set(gca,'ColorScale','log')
caxis([ax_min ax_max])
c.Label.String = 'Modulus (Pa)';
title('Ref_model_modulus');
subplot(1,2,2);
h=pcolor(opt_model_k.mod_img);
colormap(hot)
set(h, 'EdgeColor', 'none');
set(gca,'visible','off');
c = colorbar;
set(gca,'ColorScale','log')
caxis([ax_min ax_max])
c.Label.String = 'Modulus (Pa)';
title('Opt_model_modulus');
drawnow;
saveas(fig,fullfile([result_folder,'\1_modulus_maps'],fig_filename),'png')

채택된 답변

Constantino Carlos Reyes-Aldasoro
The issue is that you are setting the axis to off with this
set(gca,'visible','off');
Your problem will be solved if you use
set(gca,'visible','on');
Notice that the title will be interpreted as a latex string, so the _ will convert the text. To avoid this you can use
title('Ref_model_modulus','interpreter','none');
Problem solved?
  댓글 수: 3
Constantino Carlos Reyes-Aldasoro
You can always insert other objects, but setting to visible would be the easiest. If what you do not want is the ticks on the axes themselves, you can remove those texts in particular easily like this:
>> set(gca,'xtick',[])
>> set(gca,'ytick',[])
Hope this solves the question, if it does, please accept the answer. If it does not, do let me know.
Koen Franse
Koen Franse 2021년 2월 10일
Yes that solves the problem, thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by