【发布时间】:2014-05-05 14:13:53
【问题描述】:
我有一个创建和捕获 jpg 文件的代码。但是,它往往会出现两种不同的图像尺寸。当我想将 jpg 文件制作成电影时,这会成为一个问题。我已经设置了PaperPosition 和其他一些东西,但它仍然有两种图像尺寸。图像大小的变化似乎是随机的,因为如果我运行两次代码,之前具有其中一种尺寸的图像现在可能具有另一种尺寸。
nFrames = 8797; % Number of frames. Number of days between 1/1/1990 and 1/31/2014
for k = 1:nFrames % 1/1/1990 to the number of days.
% Map of conterminous US
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'});
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_O3{k}), str2double(Lon_O3{k}), 40, str2double(data_O3{k})*1000, 'filled'); % Plot a dot at each Lat and Lon
hold on
% Colorbar
caxis([10 90]);
h = colorbar;
ylabel(h,'ppb');
% Title
% date = datenum(2007, 04, 29) + k; % Convert t into serial numbers.
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
% Set size of image
set(gcf,'Units','points')
set(gcf,'PaperUnits','points')
size = get(gcf,'Position');
size = size(3:4);
set(gcf,'PaperSize',size)
set(gcf,'PaperPosition',[0,0,size(1),size(2)])
% Save as jpg (just specify other format as necessary) - Must set 'facecolor' to 'none' or else color of states turn out black
eval(['print -djpeg map_US_' datestr(cell2mat(date_O3(k)),'yyyy_mm_dd') '_O3_MDA8.jpg']);
% saveas(gca, ['WI_' datestr(cell2mat(Date)) '_PM25.jpg']);
clf
end
% Save as AVI file - Set 'facecolor' to 'white'. It looks better.
close(gcf)
如何设置图像大小(希望像我在set(ax, ...) 中尝试那样设置为全屏,这样当我保存 jpg 文件时,它们的大小都相同?
【问题讨论】:
-
我已经使用
subplot('position',[0 0 1 1]);取得了一些成功,它基本上是“在整个窗口中”绘制的。此外 - 如果轴标签等的内容发生变化,大小可能会发生变化。您是否尝试在所有轴关闭的情况下进行绘图? -
你把
subplot命令放在哪里了?我没有axeson是吗?在哪里? -
我将
subplot放置在创建图形之后和创建绘图之前:figure; subplot('position',[0 0 1 1]); plot(X, Y); axes off;。我承认不熟悉地理绘图例程,因此这可能不适用于您的情况。没有图片或数据很难重现您的问题。
标签: image matlab plot image-size