Open In App

How to Use Tex (latex Math Mode) Symbols in Legends and Labels in MATLAB Figures?

Last Updated : 09 Nov, 2022
Like Article

MATLAB provides options to add legends to plots and labels to figures with simple functions. Now, there are many cases when a user needs to display Latex symbols in the legends and label plots and figures. In this article, we shall see how to use Latex symbols in Legends and Labels in MATLAB figures. 

Latex Symbol in Legends of Figures/Plots:

See this article to learn how to add legends to axes in MATLAB. Now, to add Latex symbols in the legend, you need to add the latex code in $$ and then set the interpreter to latex.  



legend(‘$<curve-1>$,’$<curve-2$’,…,”$<curve-n>$’, ‘Interpreter’, ‘latex’)

See the following examples to understand it better. Let us plot a graph that calculates the sin and cos of a variable δ and add the same to legend and x, y labels.

Example 1:


% MATLAB code for add Latex symbol 
% Horizontal axis range
x = linspace(-3,9,10000);    
% Plotting sin and cos on same graph
hold on
hold off
% Adding legend with latex symbols
% Adding axes labels with latex symbols


Legend with Latex symbol ‘δ’

We can add Latex legends with latex symbols to multiple axes as well. See the following implementation.

Example 2:


% MATLAB code for add Latex legends 
% with latex symbols to multiple axes
% Defining multiple axes
ax1=axes('Position',[.1 .1 .4 .4]);
ax2=axes('Position',[.53 .53 .4 .4]);
% Creating horizontal range
x = linspace(-3,3,10000); 
% Plotting in axes 1
% Adding latex symbols in legend in axes 1
% Plotting in axes 2
% Adding latex symbols in legend in axes 1



Latex Symbols in Labels of Figures/Plots in MATLAB:

As seen in the above examples, we can add latex symbols in the legends. Now, we shall see how to add latex symbols in labels of plots and figure components with an example each. We shall first see how to add latex symbols to x and y labels in a graph figure.


xlabel(‘$<latex_label>$’, ‘Interpreter’, ‘latex’)

ylabel(‘$<latex_label>$’, ‘Interpreter’, ‘latex’)

We will now add the θ symbol in x label.

Example 3:


% Latex Symbols in Labels of Figures/Plots in MATLAB
x = linspace(-3,3,10000); 
% Plotting inverse tangent function
% Adding x and y labels with theta




Now, we will add a label to a figure component with latex symbols included. For the presentation, we shall display the Laplace Equation on the label.

Example 4:


% MATLAB code for label to a figure 
% component with latex symbols
% Creating an empty uifigure
f = uifigure;    
% Creating a label with position and size of 123x123
lab = uilabel(f,'Position',[123 123 123 123]);    
% Adding latex text to label
lab.Text = ('$$\frac{\partial^2 u}{{\partial}x^2} +
\frac{\partial^2 u}{{\partial}y^2} = 0$$');
% Changing the uilabel interpreter to latex



Similar Reads

How to Use & and && Operator in MATLAB?
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. An operator is a symbol that operates on a value to perform specific mathematical or logical computations. They form the foundation of any programming language. Here we see &amp; and
3 min read
How To Use | and || Operator in MATLAB?
In MATLAB, | and || are both logical operators that are used to perform logical OR operations on Boolean variables, however, there is a subtle difference between the two: ||| The element-wise logical OR operator "|" takes two arrays of the same size and returns an array of the same size where each element is the result of the logical OR operation b
4 min read
How to Use Logical Operator Within If Statements in MATLAB?
Logical Operators are used to combining two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a boolean value either true or false. Like any other programming language, logical operators in MATLAB are beneficial, and in this article, we wil
4 min read
How To Use Different Images or Colormaps on a Same Figure into MATLAB?
A color map is a matrix-based value that is used to define the colors for graphical representation in MATLAB. MATLAB has some functions that are used to draw the objects by mapping data values to the color map. The color map is formulated in three columns wide and each row contains three elements RGB (red, green, blue) triplet. in colormap RGB the
4 min read
Difference Between MATLAB and Scilab
Performing computation with the help of programming languages was always been a focus for all mathematicians and statistician. Whereas to perform it efficiently it also depends on the scope of the problem. We have a variety of tools and languages to analyze and compute data. So let us discuss the most commonly used languages. 1. MATLAB : MATLAB is
2 min read
Classes and Object in MATLAB
A class is a blueprint that defines the variables and the methods which provide a commonly shared basis for its corresponding objects. It defines an object that encapsulates data and the operations performed on that data. classdef is a keyword used to define MATLAB classes. Syntax to define a class: classdef (Attributes) ClassName &lt; SuperclassNa
4 min read
Differences Between MATLAB and R Programming Language
MATLAB: MATLAB stands for Matrix Laboratory. MATLAB is a high performance language, initially intended to provide access to the matrix software designed by the projects LINPACK (Linear System Package) and EISPACK (Eigen System Package). It incorporates the environment for computation, visualization and programming. MATLAB provides a modern language
4 min read
Difference Between MATLAB and Octave
1. MATLAB : MATLAB is a multi-paradigm numerical computing environment and a high-performance language that is used for technical computing. The name MATLAB stands for matrix laboratory. It was developed by Cleve Moler of the company MathWorks.Inc in the year 1984. It is written in C, C++, Java. It allows matrix manipulations, plotting of functions
2 min read
Arithmetic Encoding and Decoding Using MATLAB
Arithmetic coding is a type of entropy encoding utilized in lossless data compression. Ordinarily, a string of characters, for example, the words "hey" is represented for utilizing a fixed number of bits per character. In the most straightforward case, the probability of every symbol occurring is equivalent. For instance, think about a set of three
6 min read
Single Side Band (SSB) Modulation and Demodulation using MATLAB
Single sideband (SSB) modulation might be a sort of modulation used to send data, which includes an audio signal. Amplitude modulation produces an output signal in which the bandwidth is two times the most frequency of the original baseband signal. SSB modulation neglects this bandwidth increase, and also the power wasted on a carrier, at the price
2 min read
Article Tags :