Add subtitle to plot - MATLAB subtitle (2024)

Add subtitle to plot

Since R2020b

collapse all in page

    Syntax

    subtitle(txt)

    subtitle(___,Name,Value)

    subtitle(target,___)

    t = subtitle(___)

    Description

    example

    subtitle(txt) adds the specified subtitle text to the current axes.

    example

    subtitle(___,Name,Value) sets properties on the text object using one or more name-value pair arguments. Specify the properties after all other input arguments. For a list of properties, see Text Properties.

    example

    subtitle(target,___) specifies the target object for the subtitle. The target object can be any type of axes, a tiled chart layout, or an array of objects. Specify the target object before all other input arguments.

    example

    t = subtitle(___) returns the text object for the subtitle. Use t to set properties on the object after creating the subtitle. For a list of properties, see Text Properties.

    Examples

    collapse all

    Add Subtitle

    Open Live Script

    Create a plot. Add a title with the title function. Then add a subtitle with the subtitle function.

    plot([0 2],[1 5])title('Straight Line')subtitle('Slope = 2, y-Intercept = 1')

    Add subtitle to plot - MATLAB subtitle (1)

    Include Variable in Subtitle

    Open Live Script

    Create a plot, and add a title to the plot. Define slopevalue and yintercept as numeric variables. Define txt as a combination of literal text and the values of slopevalue and yintercept converted to character vectors. Then, pass txt to the subtitle function to display the subtitle.

    plot([0 2],[1 5])title('Straight Line')slopevalue = 4;yintercept = 1;txt = ['Slope = ' int2str(slopevalue) ', y-Intercept = ' int2str(yintercept)];subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (2)

    Change the Subtitle Color

    Create a plot. Add a title with the title function. Then, call the subtitle function, and specify the color using the 'Color' name-value pair argument. The color can be a color name, such as 'red', or you can specify a custom color using an RGB triplet or hexadecimal color code. In this case, specify 'red'.

    plot([0 2],[1 5])title('Straight Line')subtitle('Slope = 2, y-Intercept = 1','Color','red')

    Add subtitle to plot - MATLAB subtitle (3)

    Alternatively, call the subtitle function with an output argument to return the text object. Then set the color on the text object. In this case, specify the hexadecimal color code '#DD5500'.

    txt = subtitle('Plot of y = 2x + 1');txt.Color = '#DD5500';

    Add subtitle to plot - MATLAB subtitle (4)

    Create Multicolored Subtitle Using TeX Markup

    Open Live Script

    Create a plot, and add a title with the title function. Create a character vector containing TeX markup with custom colors for different words in the subtitle. Then pass the character vector to the subtitle function.

    plot([0 2],[1 5])title('Straight Line')txt = ['An {\color{magenta}Attractive '...'\color[rgb]{0 .5 .5}and \color{red}Colorful} Subtitle'];subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (5)

    Include Greek Symbols

    Open Live Script

    Create a histogram, and add a title with the title function. Create a character vector containing TeX markup with Greek symbols. Then pass the character vector to the subtitle function.

    histogram(5*randn(1,50)+10)title('Population Data')txt = '{\it\mu} = 10, {\it\sigma} = 5';subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (6)

    Include Superscripts and Subscripts

    Open Live Script

    Create a histogram, and add a title with the title function. Create a character vector containing TeX markup that displays subscripts and superscripts. Then pass the character vector to the subtitle function.

    x = -10:0.1:10;y1 = x.^2;y2 = 2*x.^2;plot(x,y1,x,y2);title('Exponential Functions')txt = 'y_1 = x^2 and y_2 = 2x^{2 + k}';subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (7)

    To display an italic font for the variables, add the \it modifier.

    txt = '{\ity}_1 = {\itx}^2 and {\ity}_2 = 2{\itx}^{2 + \itk}';subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (8)

    Create Multiline Subtitle

    Create a plot, and add a title with the title function. Then create a subtitle containing two lines of text by passing a cell array of character vectors to the subtitle function. Each element in the array is a separate line of text.

    plot([0 2],[1 5])title('Straight Line')txt = {'Slope = 2','y-Intercept = 1'};subtitle(txt)

    Add subtitle to plot - MATLAB subtitle (9)

    Display TeX Characters as Typed

    Open Live Script

    Create a plot with a title. Then create a subtitle containing an underscore character that the TeX interpreter normally uses for subscripts. Set the Interpreter to 'none' when you call the subtitle function, so that the underscore character appears in the subtitle.

    plot([0 2],[1 5])title('Straight Line')subtitle('y_1 = 2x + 1','Interpreter','none')

    Add subtitle to plot - MATLAB subtitle (10)

    Change Alignment of Title and Subtitle

    Open Live Script

    Create a plot and add a title and a subtitle. Get the current axes, and align the title and subtitle to the left edge of the plot box by setting the TitleHorizontalAlignment property on the axes to 'left'.

    plot([0 2],[1 5])title('Straight Line')subtitle('Slope = 2, y-Intercept = 1')ax = gca;ax.TitleHorizontalAlignment = 'left';

    Add subtitle to plot - MATLAB subtitle (11)

    Center the title and subtitle by setting the TitleHorizontalAlignment property on the axes to 'center'.

    ax.TitleHorizontalAlignment = 'center';

    Add subtitle to plot - MATLAB subtitle (12)

    Specify Target Axes

    Open Live Script

    Create two plots in a tiled chart layout. Then add a title and subtitle to each plot.

    t = tiledlayout(1,2);% Left plotax1 = nexttile;plot([0 2],[1 5])title(ax1,'A Straight Line')subtitle(ax1,'Slope = 2, y-Intercept = 1')% Right plotax2 = nexttile;plot([0 2],[2 8])title(ax2,'Another Straight Line')subtitle(ax2,'Slope = 3, y-Intercept = 2')

    Add subtitle to plot - MATLAB subtitle (13)

    Input Arguments

    collapse all

    txtSubtitle text
    character vector | cell array of character vectors | string array

    Subtitle text, specified as a character vector, cell array of character vectors, or a string array. To create multiple lines of text, specify a cell array of character vectors or a string array.

    Example: subtitle('Single Line Subtitle')

    Example: subtitle(["Subtitle With" "Multiple Lines"])

    targetTarget for the subtitle
    axes | tiled chart layout | array of objects

    Target for the subtitle, specified as one of the following:

    • Any type of axes: an Axes, PolarAxes, or GeographicAxes object.

    • A TiledChartLayout object.

    • An array of graphics objects from the preceding list. The objects must belong to the same class. To determine the class, use the class function.

    If you do not specify the target for the subtitle, then the subtitle function adds the subtitle to the graphics object returned by the gca command.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: subtitle('My Subtitle','FontSize',12) specifies a 12-point font size.

    Note

    The properties listed here are only a subset. For a complete list, see Text Properties.

    FontSizeFont size
    11 (default) | scalar value greater than 0

    Font size, specified as a scalar value greater than 0 in point units. One point equals 1/72 inch. To change the font units, use the FontUnits property.

    If you add a title or subtitle to an axes object, then the font size property for the axes also affects the font size for the title and subtitle. The title and subtitle font sizes are the axes font size multiplied by a scale factor. The FontSize property of the axes contains the axes font size. The TitleFontSizeMultiplier property of the axes contains the scale factor. By default, the axes font size is 10 points and the scale factor is 1.1, so the title and subtitle each have a font size of 11 points.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    FontWeightThickness of text characters
    'normal' (default) | 'bold'

    Thickness of the text characters, specified as one of these values:

    • 'normal' — Normal weight as defined by the particular font

    • 'bold' — Thicker characters outlines than normal

    MATLAB® uses the FontWeight property to select a font from those available on your system. Not all fonts have a bold font weight. Therefore, specifying a bold font weight could still result in the normal font weight.

    The SubtitleFontWeight property for the associated axes affects the FontWeight value for the subtitle.

    Tips

    • By default, the Interactions property contains editInteraction so the text can be edited by clicking on the text. To disable this interaction, set the Interactions property of the text object to [].

    Version History

    Introduced in R2020b

    See Also

    Functions

    • title

    Properties

    • Text Properties

    MATLAB Command

    You clicked a link that corresponds to this MATLAB command:

     

    Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

    Add subtitle to plot - MATLAB subtitle (14)

    Select a Web Site

    Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

    You can also select a web site from the following list:

    Americas

    • América Latina (Español)
    • Canada (English)
    • United States (English)

    Europe

    • Belgium (English)
    • Denmark (English)
    • Deutschland (Deutsch)
    • España (Español)
    • Finland (English)
    • France (Français)
    • Ireland (English)
    • Italia (Italiano)
    • Luxembourg (English)
    • Netherlands (English)
    • Norway (English)
    • Österreich (Deutsch)
    • Portugal (English)
    • Sweden (English)
    • Switzerland
      • Deutsch
      • English
      • Français
    • United Kingdom (English)

    Asia Pacific

    • Australia (English)
    • India (English)
    • New Zealand (English)
    • 中国
    • 日本 (日本語)
    • 한국 (한국어)

    Contact your local office

    Add subtitle to plot - MATLAB subtitle (2024)

    FAQs

    How to add subtitle in matlab plot? ›

    Create a plot, and add a title to the plot. Define slopevalue and yintercept as numeric variables. Define txt as a combination of literal text and the values of slopevalue and yintercept converted to character vectors. Then, pass txt to the subtitle function to display the subtitle.

    How to add overall title to subplot in Matlab? ›

    sgtitle( txt ) adds a title above the grid of subplots in the current figure. If a figure does not it exist, then this command creates one. sgtitle( target , txt ) adds the title to the subplot grid in the specified figure, panel, or tab, instead of the current figure.

    How do you align a plot title to the left in Matlab? ›

    Change Title Alignment

    Create a plot with a title. Get the current axes, and then align the title to the left edge of the plot box by setting the TitleHorizontalAlignment property of the axes to 'left' .

    How to change font size of graph title in Matlab? ›

    To make the font size smaller for the entire axes, set the FontSize property. Changing this property affects the font for the title, tick labels, and axis labels, if they exist. To display the title across two lines, use a cell array with curly brackets {} to define a multiline title.

    How do I manually add subtitles? ›

    Go to View > Subtitles > Add Subtitle File. In the Open File dialog box, select the subtitle file that you want to add. The subtitles will be added to the video. To adjust the timing of the subtitles, go to View > Subtitles > Subtitle Delay.

    How do I add a title to a subplot? ›

    When adding a title to a plot or a subplot, the set_text() function is usually used with the get_title() function, which is a method of the Axes class and is used to get the title object for the current subplot. t_obj: is a text object such as a label or title. Text_s: is the text to set.

    How do you add a legend title to a plot in Matlab? ›

    To add a legend title, set the String property of the legend text object. To change the title appearance, such as the font style or color, set legend text properties. For a list, see Text Properties.

    How do you add labels to subplots? ›

    By using the set_xlabel() function, you can not only add labels to your subplots but also customize their appearance to suit your needs. Remember, effective data visualization is not just about presenting data; it's about telling a story. And clear, descriptive labels are an essential part of that story.

    How to label plot legend in MATLAB? ›

    Alternatively, you can specify the legend labels using the DisplayName property. Set the DisplayName property as a name-value pair when calling the plotting functions. Then, call the legend command to create the legend. Legends automatically update when you add or delete a data series.

    How do you start a new line in a plot title in MATLAB? ›

    When displaying text on plots, "\n" is typically interpreted as '\' followed by 'n' instead of the newline character. To generate multiple lines, use cell arrays. This is done by separating each string line of text with a comma and enclosing all comma-separated strings in curly braces as follows.

    Which command gives a title to the graph plotted by MATLAB? ›

    Explanation: The title() command is used to provide a title to the graph plotted in MATLAB. It can be provided from the taskbar of the window which opens due to the plot command.

    How to change font style in MATLAB plot? ›

    Change Font in Plot

    Create a plot containing two lines with a title and a legend. Change the font to Courier. Before R2023a: Specify gcf as the first argument to the fontname function. For example, fontname(gcf,"courier") .

    How do you text fontsize a plot in MATLAB? ›

    Change Font Size in Plot

    Create a plot containing two lines with a title and a legend. Increase the font size to 16 points. Before R2023a: Specify gcf as the first argument to the fontsize function. For example, fontsize(gcf,16,"points") .

    How to put text on a graph in MATLAB? ›

    To add text to one point, specify x and y as scalars. To add text to multiple points, specify x and y as vectors with equal length. text( x , y , z , txt ) positions the text in 3-D coordinates. text(___, Name,Value ) specifies Text object properties using one or more name-value pairs.

    How do I add SRT subtitles? ›

    How to add SRT to Video?
    1. Upload your Video file. Select the Video which you want to burn your subtitle file.
    2. Upload the SRT file. Or click on "autogenerate subtitles" with Happy Scribe.
    3. Download the Video. It will take a few minutes until your Video file is ready.

    How do you add subtitles to a storyline? ›

    Under the options tab on the Storyline ribbon, click the plus sign next to captions. Find the caption file you want to import and then click open. You can also import captions by right-clicking the video placeholder or the speaker icon. The Size and Position window will open.

    How to do subscript in matlab plots? ›

    Include Superscript and Subscript in Axis Labels

    Use the '^' and '_' characters to include superscripts and subscripts in the axis labels. Use curly braces {} to modify more than one character.

    How do you add a title to an image in Matlab? ›

    title( target ,___) adds the title to the specified target object. t = title(___) returns the object used for the title.

    Top Articles
    Latest Posts
    Article information

    Author: Sen. Ignacio Ratke

    Last Updated:

    Views: 5497

    Rating: 4.6 / 5 (56 voted)

    Reviews: 87% of readers found this page helpful

    Author information

    Name: Sen. Ignacio Ratke

    Birthday: 1999-05-27

    Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

    Phone: +2585395768220

    Job: Lead Liaison

    Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

    Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.