How to put separate titles above multiple pcolor subplots
4 views (last 30 days)
Show older comments
Koen Franse
on 2 Feb 2021
Commented: Koen Franse
on 10 Feb 2021
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')
0 Comments
Accepted Answer
Constantino Carlos Reyes-Aldasoro
on 2 Feb 2021
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 Comments
Constantino Carlos Reyes-Aldasoro
on 8 Feb 2021
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.
More Answers (0)
See Also
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!