How to put separate titles above multiple pcolor subplots

4 Ansichten (letzte 30 Tage)
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')

Akzeptierte Antwort

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 Kommentare
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 am 10 Feb. 2021
Yes that solves the problem, thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by