Add Title and Axis Labels to Chart

This example shows how to add a title and axis labels to a chart by using the titlexlabel, and ylabel functions. It also shows how to customize the appearance of the axes text by changing the font size.

Create Simple Line Plot

Create x as 100 linearly spaced values between 2π and 2π. Create y1 and y2 as sine and cosine values of x. Plot both sets of data.

x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
figure
plot(x,y1,x,y2)

Add Title

Add a title to the chart by using the title function. To display the Greek symbol π, use the TeX markup, \pi.

title('Line Plot of Sine and Cosine Between -2\pi and 2\pi')

Add Axis Labels

Add axis labels to the chart by using the xlabel and ylabel functions.

xlabel('-2\pi < x < 2\pi') 
ylabel('Sine and Cosine Values') 

Add Legend

Add a legend to the graph that identifies each data set using the legend function. Specify the legend descriptions in the order that you plot the lines. Optionally, specify the legend location using one of the eight cardinal or intercardinal directions, in this case, 'southwest'.

legend({'y = sin(x)','y = cos(x)'},'Location','southwest')

Change Font Size

Axes objects have properties that you can use to customize the appearance of the axes. For example, the FontSize property controls the font size of the title, labels, and legend.

Access the current Axes object using the gca function. Then use dot notation to set the FontSize property.

ax = gca;
ax.FontSize = 13;

Title with Variable Value

Include a variable value in the title text by using the num2str function to convert the value to text. You can use a similar approach to add variable values to axis labels or legend entries.

Add a title with the value of sin(π)/2.

k = sin(pi/2);
title(['sin(\pi/2) = ' num2str(k)])

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.

Machine Learning in MATLAB

Train Classification Models in Classification Learner App

Train Regression Models in Regression Learner App

Distribution Plots

Explore the Random Number Generation UI

Design of Experiments

Machine Learning Models

Logistic regression

Logistic regression create generalized linear regression model - MATLAB fitglm 2

Support Vector Machines for Binary Classification

Support Vector Machines for Binary Classification 2

Support Vector Machines for Binary Classification 3

Support Vector Machines for Binary Classification 4

Support Vector Machines for Binary Classification 5

Assess Neural Network Classifier Performance

Naive Bayes Classification

ClassificationTree class

Discriminant Analysis Classification

Ensemble classifier

ClassificationTree class 2

Train Generalized Additive Model for Binary Classification

Train Generalized Additive Model for Binary Classification 2

Classification Using Nearest Neighbors

Classification Using Nearest Neighbors 2

Classification Using Nearest Neighbors 3

Classification Using Nearest Neighbors 4

Classification Using Nearest Neighbors 5

Linear Regression

Linear Regression 2

Linear Regression 3

Linear Regression 4

Nonlinear Regression

Nonlinear Regression 2

Visualizing Multivariate Data

Generalized Linear Models

Generalized Linear Models 2

RegressionTree class

RegressionTree class 2

Neural networks

Gaussian Process Regression Models

Gaussian Process Regression Models 2

Understanding Support Vector Machine Regression

Understanding Support Vector Machine Regression 2

RegressionEnsemble