how to save plot with its background color without the gray color

Hello guys
Here i wanted to save a plot having an orange background color. An example code is shown below:
b_col = [255, 150, 0]; % orange color code
b_col = b_col./255;
plot(rand(10,1));
set(gca,'color',b_col);
set(gcf,'inverthardcopy','off');
print('test','-djpeg','-r900')
The above code result in a plot with orange background color, however, when i save it contains a gray color surrownding it as shown in the test image file below. At this point i needed a support in removing a gray color but instead replaced by white color.
Thanks for your supporting

 채택된 답변

b_col = [255, 150, 0]; % orange color code
b_col = b_col./255;
f = figure;
f.Color = [1 1 1]; % Set the color to white
plot(rand(10,1));
set(gca,'color',b_col);

댓글 수: 1

Dear Simon, thank you for the quick response. Your suggestion fixed the gray color problem, however while i print it the orange color is converted to white too, which is not the case i wanted.
I used the comand below to save my plot.
print('test','-djpeg','-r900')

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 4월 16일

0 개 추천

Try exportgraphics() instead of print().

댓글 수: 3

Hello Dear
i used your suggestion as follow
ax = gca;
exportgraphics(ax,'test_1.jpg')
however, it result in error messages below:
error ('Undefined function or variable
'exportgraphics'.)
Best
@TESFALEM ALDADA, you forgot to list your version when you posted. You must have an old version. exportgraphics() was introduced in r2020a.
TESFALEM ALDADA
TESFALEM ALDADA 2022년 4월 17일
편집: TESFALEM ALDADA 2022년 4월 17일
@Image Analyst, yes sure i am using a Matlab version is r2019a.

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2022년 4월 16일

편집:

2022년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by