Plot size varies even when plotting in a loop
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello all,
I wrote a loop that reads a set of data files, makes a plot using the data in each file, exports the plot to a png file, and continues.
Since this is done in a loop using a counter, I expect the images saved in png format to be the same size and resolution. However, the images seem to be of different sizes/positions, so when I try to assemble the png files to produce a movie, the movie appears to flicker or jerk.
Here is the body of the loop. Any thoughts would be appreciated.
Thanks.
for it = 1: nt
data = dlmread([pathName0 timeList{it} '/' var '_planeXY.raw'], '', 2, 0);
x = data(:, 1);
y = data(:, 2);
z = data(:, 4);
t1 = num2str(t(it, 1)*1.0e03);
xlin = linspace(0, max(x), 300);
ylin = linspace(min(y), max(y), 300);
[X, Y] = meshgrid(xlin, ylin);
Z = griddata(x, y, z, X, Y, 'cubic');
h = figure();
colormap(jet);
grid off;
surf(xlin/1e-03, ylin/1e-03, Z, 'Edgecolor', 'none');
shading interp;
view(2);
cb = colorbar();
set(cb, 'ytick', [0 0.05 0.1 0.15 0.2]);
cbTitle = get(cb, 'Title');
set(cbTitle ,'String', varName);
caxis([0 0.2]);
ylabel('$r$ [mm]', 'Interpreter', 'latex', 'Fontname', 'Times', 'Fontsize', 40);
xlabel('$z$ [mm]', 'Interpreter', 'latex', 'Fontname', 'Times', 'Fontsize', 40);
title(['Time: ' t1 ' [ms]'], 'Fontname', 'Times', 'Fontsize', 40);
yticks([-30 -20 -10 0 10 20 30]);
xticks([0 10 20 30 40 50 60 70 80]);
ax = gca();
set(ax, 'Fontname', 'Times', 'Fontsize', 24);
axis([0 80 -35 35]);
print(h, '-dpng', [caseLES '/' timeList{it} '.png']);
close all;
end
댓글 수: 1
dpb
2020년 1월 20일
If you want a specific resolution, use the key -r on the command line followed by the desired resolution.
답변 (1개)
Prabhan Purwar
2020년 1월 23일
Hi,
Following links may help:
- https://in.mathworks.com/help/matlab/creating_plots/save-figure-at-specific-size-and-resolution.html (Save Figure at Specific Size and Resolution)
- https://in.mathworks.com/matlabcentral/answers/384848-get-figures-and-use-them-to-build-a-video-avi (Get figures and use them to build a video)
- https://in.mathworks.com/matlabcentral/answers/280635-make-video-from-images (Make video from images)
Hope it helps!!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!