'MATLAB Subplot Make Figure Larger

I am plotting two maps next to each other using subplot. However, now, the image is turning out like this: enter image description here

Is there any way to make the map part of the image larger? I would like to plot the maps side by side, by in this image, the resolution is low and the size is small.

%% Graph one site at a time
nFrames = 6240; % Number of frames. 
for k = 94:nFrames 
    h11 = subplot(1,2,1); % PM2.5
    % Map of conterminous US
    ax = figure(1);
    set(ax, 'visible', 'off', 'units','normalized','outerposition',[0 0 1 1]);     
    ax = usamap('conus');
    set(ax,'Position',get(h11,'Position'));
    delete(h11);
    states = shaperead('usastatelo', 'UseGeoCoords', true,...
        'Selector',...
        {@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
    faceColors = makesymbolspec('Polygon',...
        {'INDEX', [1 numel(states)], 'FaceColor', 'none'}); % NOTE - colors are random
    geoshow(ax, states, 'DisplayType', 'polygon', ...
        'SymbolSpec', faceColors)
    framem off; gridm off; mlabel off; plabel off

    hold on

    % Plot data
    scatterm(ax,str2double(Lat_PM25{k})', str2double(Lon_PM25{k})', 25, str2double(data_PM25{k})', 'filled'); 

    % Colorbar
    caxis([5 30]);
    h = colorbar;
    ylabel(h,'ug/m3');

    % Title
    title(['PM2.5 24-hr Concentration ', datestr(cell2mat(date_PM25(k)), 'mmm dd yyyy')]); 

    %%%%
    h22 = subplot(1,2,2); % O3
    % Map of conterminous US
    ax2 = usamap('conus');
    set(ax2,'Position',get(h22,'Position'));
    delete(h22);
    states = shaperead('usastatelo', 'UseGeoCoords', true,...
        'Selector',...
        {@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
    faceColors = makesymbolspec('Polygon',...
        {'INDEX', [1 numel(states)], 'FaceColor', 'none'}); % NOTE - colors are random
    geoshow(ax2, states, 'DisplayType', 'polygon', ...
        'SymbolSpec', faceColors)
    framem off; gridm off; mlabel off; plabel off

   hold on

    % Plot data
    scatterm(ax2,str2double(Lat_O3{k})', str2double(Lon_O3{k})', 25, str2double(data_O3{k})'*1000, 'filled'); 
hold on

    % Colorbar
    caxis([10 90]);
    h = colorbar;
    ylabel(h,'ppb');

    % Title
    title(['O3 MDA8 Concentration ', datestr(cell2mat(date_O3(k)), 'mmm dd yyyy')]); % Title changes every daytitle(str);

    % Capture the frame
    mov(k) = getframe(gcf); % Makes figure window pop up

     % Save as jpg
    eval(['print -djpeg map_US_' datestr(cell2mat(date_PM25(k)),'yyyy_mm_dd') '_PM25_24hr_O3_MDA8.jpg']);

    clf

end

close(gcf)


Solution 1:[1]

This blog post has many great examples of FileExchange scripts dealing with size of subplots.

subplot_tight works very well and makes the subplots larger. Instead of writing in subplot(1,2,1), use subplot_tight(1,2,1)

Solution 2:[2]

To change the amount of space the data occupies in the figure, you can use this command:

set(gca,'Position',[0.1 .1 0.75 0.85])

You'll have to play with the numbers a bit, to get things look nice. Note that Matlab rescales everything when you resize the figure window, so the optimal numbers depend on the window size you want to use.

On the other hand, you want to make the map bigger in comparison to the colorbar. You cannot make it without changing your window size, because your maps are already as high as the color bars. I would suggest to:

  1. Set caxis to the same range in both plots.
  2. Remove the colorbar on the left one.
  3. Increase the height of your figure window to make the maps occupy as much width as possible.
  4. Put the two images nicelye side by side using the command above.

For more information, see Matlab Documentation on Axes Properties.

Example:

% Default dimenstions
figure
x = 1:.1:4;
y = x;
[X, Y] = meshgrid(x,y);

subplot(1,2,1)
h = pcolor(X, Y, sin(X).*cos(Y)*2);
set(h, 'EdgeAlpha', 0);
axis square
colorbar

subplot(1,2,2)
h = pcolor(X, Y, sin(Y).*cos(X));
set(h, 'EdgeAlpha', 0);
axis square
colorbar


% adjust dimensions
subplot(1,2,1)
set(gca, 'Position', [0.1 0.1 0.3 0.85])

subplot(1,2,2)
set(gca, 'Position', [0.55 0.1 0.3 0.85])

Solution 3:[3]

My problem was similar -> scaling subplots in a figure a bit more up. Important for me though, was to maintain the aspect ratio that I've set before.

Enhancing the answer from @texnic in order to not have to set the values manually, one might use the following:

scale = 1.1;                % Subplot scale

subplot(1,2,1)
% Your plotting here ...

pos = get(gca, 'Position'); % Get positions of the subplot [left bottom width height]
set(gca, 'Position', [pos(1) pos(2) pos(3)*scale pos(4)*scale]); % Scale width and height

Understanding this, one can also easily implement a parametric move of the subplot.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SugaKookie
Solution 2
Solution 3 Michal M.