필터 지우기
필터 지우기

how to save a plot with black background/border, white labels and white title to an image file

조회 수: 63 (최근 30일)
The following code produces what I want, a plot with a black background, black border, white labels, ticks, and title (see file screen.PNG).
figure(1)
plot([0,1],[0,1])
xlabel('x-label')
ylabel('y-label')
title('title','Color','w')
set(gcf,'Color',[0 0 0]); % color of the frame around the figure
set(gca,'Color','k')%color for the plot area
set(gca,'XColor',[1 1 1]); % Set RGB value to what you want
set(gca,'YColor',[1 1 1]); % Set RGB value to what you want
saveas(gcf,'myfigure.png'); % save as .png file
Nonetheless, the file saved by saveas has a white border without ticks, labels, or title (see saved.png). I obtain the same result if I save it through the File menu. If I print it to a pdf file, my result has white background, white border, black labels, black ticks, and black title (see printed pdf).
How could I save an image file that looks like figure(1)? Your help and advice will be kindly appreciated.

채택된 답변

Kevin Holly
Kevin Holly 2022년 7월 21일
You could use getframe to capture the axes as an image.
  댓글 수: 3
Kevin Holly
Kevin Holly 2022년 7월 21일
편집: Kevin Holly 2022년 7월 21일
try
F=getframe(gcf)
F = struct with fields:
cdata: [433×577×3 uint8] colormap: []
to get an image of the entire figure window.
figure(1)
plot([0,1],[0,1])
xlabel('x-label')
ylabel('y-label')
title('title','Color','w')
set(gcf,'Color',[0 0 0]); % color of the frame around the figure
set(gca,'Color','k')%color for the plot area
set(gca,'XColor',[1 1 1]); % Set RGB value to what you want
set(gca,'YColor',[1 1 1]); % Set RGB value to what you want
F=getframe(gcf);
imshow(F.cdata)
Joaquin Salas
Joaquin Salas 2022년 7월 21일
That worked pretty well! Thanks! I deeply appreciate your support, right to the point and timely. Thanks much.
Here is the code.
%%%%%%%%%%%%
figure(1)
plot([0,1],[0,1])
xlabel('x-label')
ylabel('y-label')
title('title','Color','w')
set(gcf,'Color',[0 0 0]); % color of the frame around the figure
set(gca,'Color','k')%color for the plot area
set(gca,'XColor',[1 1 1]); % Set RGB value to what you want
set(gca,'YColor',[1 1 1]); % Set RGB value to what you want
F = getframe(gcf);
im = frame2im(F);
imwrite(im,'im_from_getframe.png');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by