%% Changing Text Properties
% This example shows how to get properties of text in MATLAB® and change text property values to customize your plot.
%
%% Text Objects
% The text function creates a text object. For example, you can plot the Bessel function and place text in the plot at the minimum value.
%
% Like all graphics objects, text objects have properties that you can view and modify. These properties have default values. The display of the text object, tx, shows the most commonly used text properties, such as String, FontSize, and Color.

x = 0:0.1:10;
y = besselj(1, x);

figure
plot(x, y)
ylim([-0.5 0.7])

xmin = 5.3;      % x value at the minimum
ymin = -0.34;    % y value at the minimum
str = ['Minimum at x = ' num2str(xmin) ', y = ' num2str(ymin)];
tx = text(xmin, ymin, str)

%
%% Get Individual Text Properties
% To access individual properties, use dot notation syntax object.PropertyName. For example, return the FontSize property of the text.

tx.FontSize

%
%% Change Text Properties
% To customize the look of your text, change property values using dot notation.

tx.HorizontalAlignment = 'center';    % set horizontal alignment to center
tx.VerticalAlignment = 'top';         % set vertical alignment to top
tx.FontSize = 11;                     % make the text larger
tx.FontWeight = 'bold';               % make the text bold

%
%% Create Axes Text Objects
% When you create a graph with a title or axis labels, MATLAB will create text objects for you.

xlabel('x')
ylabel('B_1(x)')
title('First Order Bessel function for nu = 1');

%
% Plot titles and axes labels are stored in the Title, XLabel, and YLabel properties of the axes. Get the plot title using the Title property of the axes. Then you can set the text properties for the title using dot notation.

ax = gca;                    % get the current axis
ttl = ax.Title;              % get the title text object
ttl.FontAngle = 'italic';    % set the font to italic

%
%% Use Multiline Text
% To split the text into two lines, insert a carriage return character (char(10)) into the text.

tx.String = ['The minimum of the Bessel function' char(10) ...
  'is at x = ' num2str(xmin) ', y = ' num2str(ymin)];

%
%% Get All Text Properties
% Graphics objects in MATLAB have many properties. To see all the properties of a text object, use the get command.

get(tx)

%
% Copyright 2014 The MathWorks, Inc.