我想用5個小區做一排5個小區(所以5個小區彼此相鄰)。但是,當我運行代碼時,第一個圖只會接管整個圖形區域。我如何運行它,以便每個區域都留在每個區域?MATLAB繪製整個區域的小區圖
另外,如果我想每年都在不同的行中,郵票風格,每行有5個圖表,可以使用子圖嗎?現在,我每年都會運行一次,並將每行5個圖作爲單獨的jpg文件保存。
years = 1997:2014;
for y = 1:numel(years)
subplot(1,5,1)
ax = figure(1);
set(ax, 'visible', 'off','units','normalized','outerposition',[0 0 1 1]); % Make window that shows up full sized, which makes saved figure clearer
ax = usamap('conus');
states = shaperead('usastatelo', 'UseGeoCoords', true,...
'Selector',...
{@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
geoshow(ax, states,'FaceColor', 'none')
framem off; gridm off; mlabel off; plabel off
% Plot data - For each site
for i = 1:length(uID)
scatterm(ax, str2double(Lat{i}), str2double(Lon{i}), 40, annual_avg_PM25(i), 'filled');
end
subplot(1,5,2)
ax = figure(1);
set(ax, 'visible', 'on','units','normalized','outerposition',[0 0 1 1]); % Make window that shows up full sized, which makes saved figure clearer
ax = usamap('conus'); % Etc. Same as above
% Plot data - For each site
for i = 1:length(uID)
scatterm(ax, str2double(Lat_Win{i}), str2double(Lon_Win{i}), 40, PM25_Win(i), 'filled');
end
% Title
title(['PM2.5 24-hr Winter (DJF) Seasonal Average ', num2str(years(y)-1), '-', num2str(years(y))]); % Title changes every loop - Year;
% Etc. Same format for plotting 2 more graphs
% Save as jpg
clf
end
close(gcf)
我得到這個:
編輯
我嘗試下面的代碼,這確實劇情在各自的象限的次要情節,但它攪亂了最後地塊的大小由於彩條,並且標題不限於象限。我可以調整標題的大小,但有沒有更優雅的解決方案?另外,空白不能有效使用。
years = 1997:2014;
for y = 1:numel(years)
ax = figure(1);
set(ax, 'visible', 'on','units','normalized','outerposition',[0 0 1 1]); % Make window that shows up full sized, which makes saved figure clearer
%% Annual average PM2.5 concentration
load(['PM25_24hr_AnnualAvg_' num2str(years(y)) '.mat'], 'annual_avg_PM25', 'Date', 'Lat', 'Lon', 'uID')
subplot(1,5,1);
MapLatLimit = [20 50];
MapLonLimit = [-135.5 -44];
usamaps = shaperead('usastatelo', 'UseGeoCoords', true, ...
'BoundingBox', [MapLonLimit' MapLatLimit']);
ax = axesm('MapProjection', 'eqaconic', 'MapParallels', [],...
'MapLatLimit', MapLatLimit, 'MapLonLimit', MapLonLimit,...
'GLineStyle', '-');
geoshow(usamaps, 'DisplayType', 'polygon', 'FaceColor','none')
framem off; gridm off; mlabel off; plabel off
% Title
title(['Annual Average ', num2str(years(y))]); % Title changes every loop - Year;
% Plot data - For each site
for i = 1:length(uID)
scatterm(ax, str2double(Lat{i}), str2double(Lon{i}), 40, annual_avg_PM25(i), 'filled');
end
clear('uID', 'annual_avg_PM25', 'Lat', 'Lon')
%% Plot all the other ones in the same fashion except for the last plot, which adds a colorbar
%% Fall Seasonal Average
load(['PM25_24hr_FallAvg_' num2str(years(y)) '.mat'], 'annual_avg_PM25', 'Date', 'Lat', 'Lon', 'uID')
subplot(1,5,5);
MapLatLimit = [20 50];
MapLonLimit = [-135.5 -44];
usamaps = shaperead('usastatelo', 'UseGeoCoords', true, ...
'BoundingBox', [MapLonLimit' MapLatLimit']);
ax = axesm('MapProjection', 'eqaconic', 'MapParallels', [],...
'MapLatLimit', MapLatLimit, 'MapLonLimit', MapLonLimit,...
'GLineStyle', '-');
geoshow(usamaps, 'DisplayType', 'polygon', 'FaceColor','none')
framem off; gridm off; mlabel off; plabel off
% Plot data - For each site
for i = 1:length(uID)
scatterm(ax, str2double(str2double(Lat{i})), str2double(str2double(Lon{i})), 40, annual_avg_PM25(i), 'filled'); % Plot a dot at each Lat and Lon
end
% Colorbar
caxis([5 12])
h = colorbar; %('location', 'OutsideEast');
ylabel(h,'Concentration (ug/m3)');
% Title
title(['Fall (SON) Average ', num2str(years(y))]); % Title changes every loop - Year;
% Save as jpg
eval(['print -djpeg map_US_' num2str(years(y)) '_Subplot_AnnualSeasonalAvg_PM25_24hr.jpg']);
clf
end
end
這是我得到的圖像:
我無法確定運行你的代碼(未定義的變量'uID'),但我很確定問題在於你運行這些命令的順序。子圖調用可能需要在'ax = figure();'命令之後。 – Trogdor 2014-09-05 15:30:36
我嘗試了下ax = figure();並沒有做任何事情。 – shizishan 2014-09-05 16:06:46
使用帶有手柄的'get'和'set'命令來調整每個子圖的大小和位置。輸入'get(hsp(1))'來查看你可以改變的屬性。相當一些工作雖然..祝你好運。 – 2014-09-09 18:48:04