how to save a plot with black background/border, white labels and white title to an image file
62 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joaquin Salas
am 21 Jul. 2022
Kommentiert: Joaquin Salas
am 21 Jul. 2022
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.
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 21 Jul. 2022
3 Kommentare
Kevin Holly
am 21 Jul. 2022
Bearbeitet: Kevin Holly
am 21 Jul. 2022
try
F=getframe(gcf)
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)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!