Rick T
Rick T

Reputation: 3389

Changing font size on one line in multiline plot label in Octave

Is it possible to change the font size of one line of text in a multiline plot label using the ylabel command. If so how?

PS: I'm using Octave 5.2

I tried the code below but it gives me an error.

figure
plot((1:10).^2)
ylabel_txt1=strcat('1st line of text with smaller font') %1st line
ylabel_txt2=strcat('2nd line of text') %2nd line
ylabel({(ylabel_txt1,'fontsize',13) ;ylabel_txt2})

Upvotes: 0

Views: 448

Answers (2)

Tasos Papastylianou
Tasos Papastylianou

Reputation: 22225

Expanding my comment to an answer, since clarification was asked.
Hopefully the code is self-explanatory :)

ylabel_txt1 = '1st line of text with smaller font'; % 1st line
ylabel_txt2 = '2nd line of text';                   % 2nd line

F   = figure()
Ax1 = axes()
Ax2 = axes()

% create Ax2, make everything invisible except for ylabel
axes( Ax2 )
set( Ax2, 'color', 'none', 'xcolor', 'none', 'ycolor', 'none' )
ylabel( {ylabel_txt2, ' ', ' ', ' '}, 'fontsize', 16, 'color', 'k' );

% now 'create' Ax1 on top of Ax2
axes( Ax1 )
plot( (1:10) .^ 2 )
ylabel( ylabel_txt1, 'fontsize', 13 );

Upvotes: 1

Cem
Cem

Reputation: 1296

ylabel uses the tex interpreter by default, and tex interpreter allows changing the font size at arbitrary locations in the text using \fontsize{size}.

This is what you should be doing:

ylabel({['\fontsize{13}', ylabel_txt1]; ['\fontsize{10}', ylabel_txt2]})

For other formatting options, you can take a look at the 'Text Properties' page in documentation.

Upvotes: 1

Related Questions