Search code examples
matlabplotsizefigure

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

  • 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)