How to put separate titles above multiple pcolor subplots

6 ビュー (過去 30 日間)
Koen Franse
Koen Franse 2021 年 2 月 2 日
コメント済み: Koen Franse 2021 年 2 月 10 日
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
Constantino Carlos Reyes-Aldasoro 2021 年 2 月 2 日
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
Constantino Carlos Reyes-Aldasoro 2021 年 2 月 8 日
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 Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by