save_png
Visualization 중심의 Octave 학습 예제
course/basic/save_png.m
함수 시그니처
function save_png(fig, filename_png) 전체 코드
전체 코드를 복사해서 Octave에서 바로 실행할 수 있습니다.
function save_png(fig, filename_png)
% save_png - figure 창을 PNG 파일로 저장
% fig - figure 창의 핸들
% filename_png - PNG 파일의 파일명
screen_dpi = get(0, "ScreenPixelsPerInch");
screen_pixels = get(0, "ScreenSize"); % [x y w h] in pixels
screen_x = screen_pixels(1);
screen_y = screen_pixels(2);
screen_w = screen_pixels(3);
screen_h = screen_pixels(4);
screen_w_in = screen_w / screen_dpi;
screen_h_in = screen_h / screen_dpi;
pos_pixel = get(fig, "Position");
window_x_pix = pos_pixel(1);
window_y_pix = pos_pixel(2);
window_w_pix = pos_pixel(3);
window_h_pix = pos_pixel(4);
window_dpi = 100.0;
w_in = window_w_pix / window_dpi;
h_in = window_h_pix / window_dpi;
l_in = (screen_w_in - w_in) / 2.0;
b_in = (screen_h_in - h_in) / 2.0;
pos_in = [l_in b_in w_in h_in]; # [x y w h] in inches
figure(fig, "units", "inches", "position", pos_in);
print(fig, filename_png, "-dpng", "-r100");
figure(fig, "units", "pixels", "position", pos_pixel);
end 코드 해설
목적
Visualization 중심의 Octave 학습 예제
입력
- 파라미터: fig
- 파라미터: filename_png
출력
- 그래프/figure 출력
실행 흐름
- 시각화
- 출력 및 저장
핵심 함수/주제
pos_pixelscreen_pixelsgetfigureprint
실습 과제
- 축 범위와 라벨을 바꿔 그래프 해석성이 어떻게 달라지는지 확인해보세요.
- 핵심 함수 pos_pixel의 인자를 한 가지 바꿔 결과 변화를 기록해보세요.
- "시각화 -> 출력 및 저장" 흐름을 함수 단위로 분리해 리팩터링해보세요.
학습 팁
- 그래프 비교 시 축 범위(XLim/YLim)와 단위를 먼저 고정하면 해석 오류를 줄일 수 있습니다.
같은 카테고리의 다른 코드
- colored
course/basic/colored.m - demo-00
course/basic/demo-00.m - demo-01
course/basic/demo-01.m - demo-02
course/basic/demo-02.m - demo-03a
course/basic/demo-03a.m - demo-03b
course/basic/demo-03b.m - demo-04
course/basic/demo-04.m - demo-05
course/basic/demo-05.m - demo-06
course/basic/demo-06.m - demo-07
course/basic/demo-07.m