Axis control helps you change how the graph looks. You can set limits, labels, and styles to make your chart clear and easy to understand.
0
0
Axis control and formatting in MATLAB
Introduction
You want to zoom in on a specific part of your data in a plot.
You need to add labels to the x-axis and y-axis to explain what they show.
You want to change the scale of the axis, like switching from linear to logarithmic.
You want to customize the ticks or grid lines to improve readability.
You want to make your plot look nicer for a presentation or report.
Syntax
MATLAB
axis([xmin xmax ymin ymax]) xlabel('text') ylabel('text') title('text') set(gca, 'PropertyName', PropertyValue) grid on/off set(gca, 'XScale', 'linear' or 'log') set(gca, 'YScale', 'linear' or 'log')
axis sets the limits of the axes.
gca means 'get current axis' and lets you change properties like scale or ticks.
Examples
Set x-axis from 0 to 12 and y-axis from 0 to 120 to focus on the data range.
MATLAB
x = 1:10; y = x.^2; plot(x,y) axis([0 12 0 120])
Add labels and a title to explain the plot.
MATLAB
plot(x,y) xlabel('Time (seconds)') ylabel('Distance (meters)') title('Distance over Time')
Turn on grid lines to make it easier to read values.
MATLAB
plot(x,y) grid on
Change y-axis to logarithmic scale to better show data with large range.
MATLAB
plot(x,y) set(gca, 'YScale', 'log')
Sample Program
This program plots an exponential growth curve. It sets axis limits, labels, title, and turns on the grid for clarity.
MATLAB
x = linspace(0, 10, 100); y = exp(x/3); plot(x, y) axis([0 10 0 30]) xlabel('Time (s)') ylabel('Growth') title('Exponential Growth') grid on set(gca, 'YScale', 'linear')
OutputSuccess
Important Notes
Use axis tight to fit the axis limits exactly to your data.
Use axis equal to make the units the same length on both axes.
Changing axis scale to logarithmic helps when data spans many orders of magnitude.
Summary
Axis control lets you set limits and labels to make plots clear.
You can turn grid lines on or off to help read the graph.
Changing axis scale (linear or log) helps show data better.