Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

ASSIGNMENT # 01

SUBMIT TO
MAM AYESHA

SUBMIT BY
AIMAN NAVEED

DEPARTMENT
BS-MATHEMATICS

COURSE TITLE
COMPUTING TOOLS FOR MATHEMATICIANS

COURSE CODE
MATH-207

TOPIC
TWO-DIMENSIONAL PLOT

SUBMISSION DATE
20TH MAY,2024

IBN-E-IMAM DEGREE SCIENCE COLLEGE JPJ GUJRAT


TWO-DIMENIONAL PLOTS
A two-dimensional plot in MATLAB typically refers to a graph that displays data in two
dimensions, usually on a Cartesian coordinate system with an x-axis and a y-axis. Here's a
simple explanation of how to create a basic two-dimensional plot in MATLAB:

1. Data Preparation: First, you need data to plot. This could be experimental data,
mathematical functions, or any other form of numerical data.

2. Creating the Plot: Once you have your data, you can use MATLAB's plot function to
create the plot. The basic syntax for the plot function is:

plot (x , y )

 x is the vector containing the x-axis values.


 y is the vector containing the corresponding y-axis values.

3. Customizing the Plot (Optional): You can customize the plot by adding labels,
titles, legends, grid lines, changing line styles or colors, adjusting axis limits, and so on.
For example:
xlabel('X-axis label')
ylabel('Y-axis label')
title('Plot Title')
legend('Data 1', 'Data 2')
grid on

4. Displaying the Plot: To display the plot, use the show function:

Show

Here’s a simple example to demonstrate plotting a sine waves:


% Generate x values from 0 to 2*pi with a step of 0.1
x = 0:0.1:2*pi;

% Calculate y values as the sine of x


y = sin(x);

% Plot the sine wave


plot(x, y)

% Add labels and title


xlabel('X-axis')
ylabel('Y-axis')
title('Sine Wave Plot')

% Display the plot


Show

This code will plot a sine wave on a two-dimensional graph with labeled axes and a title. You
can modify the data and customize the plot according to your specific requirements.

Types of plot command


MATLAB provides a variety of 2D plotting functions to visualize data in different ways. Here
are some of the common types of 2D plots available in MATLAB:

1. Line Plot:

 Function: plot
 Description: The most basic type of plot, where data points are connected by lines.
Useful for showing trends over time or across categories

 Example:
x = 1:10;
y = rand(1,10);
plot(x, y);

2. Bar Graph:
 Function: bar
 Description: Uses bars to represent data. Useful for comparing quantities across
categories.

 Example:
y = [10, 20, 30, 40];
bar(y);

3. Area Plot:
 Function: area
 Description: Similar to a line plot but fills the area under the line. Useful for showing
cumulated totals over time.

 Example:
x = 1:10;
y = cumsum(rand(1,10));
area(x, y);

4. Pie Chart:
 Function: pie
 Description: Displays data as slices of a pie. Useful for showing proportions of a whole

 Example:
y = [1, 2, 3, 4];
pie(y);

5. Stem Plot:
 Function: stem
 Description: Similar to a line plot but uses stems from the x-axis to the data points.
Useful for showing discrete data.

 Example:
x = 1:10;
y = rand(1,10);
stem(x, y);

6. Histogram:
 Function: histogram
 Description: Displays the distribution of a dataset by grouping data into bins.

 Example:
data = randn(1,1000);
histogram(data);

Line Specifiers:
Line specifiers are optional and can be used to define the style and color of the line and
the type of markers (if markers are desired). The line style specifiers are:

Line Style Specifier Line Style Specifier


Solid(default) _ Dotted :
Dashed __ Dashed Dot _.

The line color specifiers are:

Line Color Specifier Line Color Specifier


red r magenta m
green g yellow y

blue b black k

cyan c white w

You might also like