help with formatting the title of a set of graphs

3 views (last 30 days)
Hi folks,
I have a set of graph which look like the attached image. Is there any way to format the title such that it doesn't appear across so many vertical lines? I would like to make the title extend to the width from one set of y axes to the other!
My code to generate the graphs is as follows:
figure;
hold on;
yyaxis left;
plot(temperature, myArea);
xlabel("Temperature (^{o}C)", "FontWeight", "bold");
ylabel("Area (%)", "FontWeight", "bold");
yyaxis right;
plot(temperature, gradArea);
ylabel("\Delta Area (%)", "FontWeight", "bold");
title(['Area and \Delta Area versus Temperature in ' runType ' Atmosphere for ' samples(i)], "FontWeight", "bold");
xlim([600 1500])
hold off;
Thanks!

Accepted Answer

Star Strider
Star Strider on 12 Sep 2022
Using the sprintf function is one option —
i = 1;
runType = 'Reducing';
samples{1} = 'AK STEEL';
title(sprintf('Area and \\Delta Area versus Temperature in \n%s Atmosphere for %s', runType, samples{i}), "FontWeight", "bold");
I inserted a carriage return-linefeed ('\n') for display purposes. Eliminmate it if necessary.
.
  3 Comments
Star Strider
Star Strider on 12 Sep 2022
No worries, and no apologies necessary!
I put a ‘newline’ ('\n') character here:
title(sprintf('Area and \\Delta Area versus Temperature in \n%s Atmosphere for %s', runType, samples{i}), "FontWeight", "bold");
↑ ← HERE
to break the line there. Change its position and add more of them if desired.
See the Text Before or After Formatting Operators (there is no direct link to it) section in the documentation section on formatSpec for more information on those and other options.
.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!