# Plotting Multiple Points in MATLAB

Learn how to efficiently plot multiple points in MATLAB using clear, concise steps and code samples. Understand the concepts behind point plots and how they can help visualize data sets effectively. …

Updated October 21, 2023

*Hey! If you love Computer Vision and AI, let's connect on Twitter or LinkedIn. I talk about this stuff all the time!*Learn how to efficiently plot multiple points in MATLAB using clear, concise steps and code samples. Understand the concepts behind point plots and how they can help visualize data sets effectively.

Introduction

MATLAB is a powerful software tool for mathematical computations, algorithm development, and data analysis. It provides various plotting options to visualize your data in many ways. One of these plot types is the “point plot,” which primarily shows points on an x-y plane representing individual data points, making it suitable for analyzing trends in different datasets.

In this tutorial, we will delve into the process of creating point plots with MATLAB and demonstrate how to visualize multiple sets of data points by utilizing different plotting methods. We will walk you through various ways of using MATLAB’s built-in functions to create beautiful and informative visualizations for your datasets.

- Preparing Data

Before diving into plotting multiple points in MATLAB, let’s consider the dataset we want to work with: a collection of three different data series, each consisting of 100 x-y coordinate pairs (i.e., 100 points). Our datasets can be represented as vectors or matrices (a matrix containing all vectors from one dimension) in MATLAB.

Data Set 1: [x_1, y_1] (first set of coordinates) Data Set 2: [x_2, y_2] (second set of coordinates) Data Set 3: [x_3, y_3] (third set of coordinates)

- Creating Point Plots in MATLAB

Now that we have prepared our datasets, let’s start plotting the points using MATLAB’s built-in functions. We will go through two primary methods for plotting multiple sets of data:

Method 1: Plot All Data Sets Together Using Different Colors and Line Styles In this method, we combine all three data sets into one large vector containing all the x-y coordinate pairs. Then, we plot this combined dataset using a different color and line style for each data series to distinguish them visually.

Step 1: Combine All Three Data Sets Combine vectors x_1, y_1, x_2, y_2, x_3, and y_3 into one large vector, e.g., [x_1 x_2 x_3; y_1 y_2 y_3]. This combined dataset will contain all the coordinate pairs from our three original datasets.

Step 2: Create a Point Plot Using Plot Function Use MATLAB’s plot function with the ‘color’, ‘linestyle’, and ‘marker’ arguments to create a point plot that plots all three data sets together while assigning different visual characteristics to distinguish them. The code would look like this:

plot(combinedDataset, ‘.’, Color=[red green blue], LineStyle=[- - -], MarkerSize=10)

This command uses red for Data Set 1, green for Data Set 2, and blue for Data Set 3. It also makes the points larger with a marker size of 10 to make them more prominent in the plot. The resulting plot will appear as follows:

Method 2: Plot Each Data Set Separately Using Different Color Schemes In this alternative method, we individually plot each data set using different colors and line styles. This approach is helpful when you want to analyze each dataset independently or compare their behavior in the plot.

Step 1: Create a Point Plot for Each Data Set Create separate point plots for Data Set 1, Data Set 2, and Data Set 3 by calling MATLAB’s plot function with the appropriate data vectors, colors, line styles, and marker sizes. You can use different color schemes to make each dataset stand out in the visual representation.

Step 2: Visualize All Point Plots Simultaneously Using Subplot Function Finally, create a single figure containing all three point plots by using MATLAB’s subplot function. It allows you to divide a plotting area into multiple sections, and in this case, we will use it to display our individual plots side-by-side or one below the other. The code for this step would be:

subplot(311); plot(x_1, y_1, ‘.’, Color=red, LineStyle='-', MarkerSize=10) subplot(322); plot(x_2, y_2, ‘.’, Color=blue, LineStyle='–', MarkerSize=15) subplot(333); plot(x_3, y_3, ‘.’, Color=green, LineStyle=':', MarkerSize=8)

This will generate a figure consisting of three subplots with the points from each data set individually plotted. The resulting figure will look like this:

Conclusion

MATLAB provides versatile tools for creating point plots to visualize multiple sets of data. By employing different methods such as plotting all datasets together or using a separate point plot for each dataset, you can achieve insightful and informative visualizations that help analyze trends in your data effectively. Incorporate these techniques into your MATLAB workflow to enhance your data analysis capabilities and create visually appealing graphics.