mycolorbar.m (OK) + subplot

Version 1.0.0.0 (312 KB) by Ser xyz
Many subplots with colorbars. The space between subplots is good by default. Ten times faster plot.
318 Downloads
Updated 23 Aug 2012

View License

I don't know the reason but the by-default "colorbar" in the latest matlab versions (for example Matlab 2012a) performs very poorly when using many subplots: the plotting is extremely slow (40 sec) and the subplots are so shrunk that you cannot even see them! (i.e. somehow the by-default colorbar forces too much unused space between suplots, so they don't fit in the figure).

Using an older version of colorbar.m (which I renamed here as "mycolorbar.m") totally solved these problems: ploting is extremely fast (4 sec) and the subplots are correct. The space between subplots is good by default too. This is the same efficient behaviour that we had when doing the by-default suplot + colorbar in the older and lighter Matlab 6.5 version.

You can compare the slow/crap by-default (new version) "colorbar" with the fast/good (old version) "mycolorbar" here. Download and save the file "mycolorbar.m" in your working folder. Open Matlab 2012a and copy-paste this:

=============================
%PROGRAM: mytestcolorbar.m

close all
clear all
format short g

%.....................
X = rand(180,360); %Fake 2D global data.
%.....................
tic
figure(1)
for i = 1:64
indexi = i
subplot(8,8,i)
imagesc(X)
set(gca,'Xtick',[])
set(gca,'Ytick',[])
%Colorbar by default (slow and crap)
hbar=colorbar('vertic');
set(hbar,'FontSize',[6])
end
print('-dpng','-r200','mytestcolorbar_fig1.png')
xtoc1 = toc;
%.....................
tic
figure(2)
for j = 1:64
indexj = j
subplot(8,8,j)
imagesc(X)
set(gca,'Xtick',[])
set(gca,'Ytick',[])
%Colorbar older version (fast and OK)
hbar=mycolorbar('vertic');
set(hbar,'FontSize',[6])
end
print('-dpng','-r300','mytestcolorbar_fig2.png')
xtoc2 = toc;
%.....................
xtoc1 %time used by colorbar-crap
xtoc2 %time used by colorbar-good
%.....................
=============================

Cite As

Ser xyz (2024). mycolorbar.m (OK) + subplot (https://www.mathworks.com/matlabcentral/fileexchange/37885-mycolorbar-m-ok-subplot), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0