Plotting (and saving) a figure with a black background

68 ビュー (過去 30 日間)
Right Grievous
Right Grievous 2013 年 9 月 9 日
コメント済み: Krystian 2022 年 1 月 26 日
Hi again,
I have another plotting question; I have 4 subplots and I want one of them to have a black background. Since I only want one to have the black background I can't use colordef.
I have tried:
set(subplot(vertical,horizontal,figure_name),'Color','k')
and:
set(gca,'color','black')
These both work to colour the subplot in the figure window but when I save the figure (as a .png) the saved subplot has a white background. I have also tried plotting a massive black patch that covers the plot area - but this also gets missed or overwritten when saving the figure!
If there are any other commands/ways to change the background colour I would love to know them.
As always any help is greatly appreciated.
Rod.

採用された回答

Image Analyst
Image Analyst 2013 年 12 月 2 日
You accepted the wrong answer. There is a way to do it. this works just fine:
subplot(2,2,1);
subplot(2,2,2);
subplot(2,2,3);
subplot(2,2,4);
set(gca,'color','black')
export_fig('yourfigure.png');
export_fig() is available here: http://www.mathworks.com/matlabcentral/fileexchange/ It's the most downloaded File Exchange submission ever, for a reason.
  2 件のコメント
Right Grievous
Right Grievous 2013 年 12 月 2 日
You are right Image Analyst, this does work with export-fig - at least with a simple plot function. My original use was with patches and bar which I guess this will also work with. The funny thing is I was using export-fig when I was trying to get a black background... I'm not sure why it wasn't working.
I left the question up for a long time and got no answers so I was just trying to tidy things up a bit. Thank you for the help!
Krystian
Krystian 2022 年 1 月 26 日
set(gca,'color','k') works as long you don't use axis off :(

サインインしてコメントする。

その他の回答 (1 件)

James Heagy
James Heagy 2022 年 1 月 7 日
While export_fig will do the job, I find that the default settings are not always ideal. If you wanted a plot with white dots on a black background you can simply do this:
h=figure(1);
plot(x,y,'w.');
set(gca,'color',[0 0 0])
set(h,'InvertHardcopy','off')
print(h,figfname,'-dtiffn');
I use -dtiffn to get a super high-res plot, then I generally open the file in Preview (on the Mac - not sure what to use on other platforms) and export the plot as a jpg.
The result from export_fig(figfname,'-tif'), by comparison, is unacceptable for publication, IMHO.
  1 件のコメント
Image Analyst
Image Analyst 2022 年 1 月 7 日
Now you can use the built-in exportgraphics() for almost every situation.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by