2
votes

I have an issue where saving my figure makes the titles disappear.

I create this figure, which looks as i want it to:

subplot(2,1,1);
title('A')
plot(A);
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
title('D')
plot(D);
hold on;
plot(E,'rs');
plot(F,'gs');

But in order to save it, I add

h= figure
...
saveas(h,namejpg,'jpg');

This saves everything apart from the titles. I want to keep the titles - why do they disappear when I define the figure?! Any help at all much appreciated.

The full code looks like this:

h=figure;
subplot(2,1,1);
title('A')
plot(A);
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
title('D')
plot(D);
hold on;
plot(E,'rs');
plot(F,'gs');
saveas(h,namejpg,'jpg');
1

1 Answers

3
votes

This happens because the title is added to the subplot, then it is cleared when plot is called. To avoid this, simply call title after calling plot, like so:

figure
subplot(2,1,1);
plot(A);
title('A')
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
plot(D);
title('D')
hold on;
plot(E,'rs');
plot(F,'gs');
saveas(h,namejpg,'jpg');