Hi Sam,
I think the type of plot you are looking for here is the "strip plot" or "dot plot." A strip plot helps us visualize the distribution of data points within each category.
In MATLAB, we can achieve this using a combination of the “scatter” function and some adjustments to position the points correctly. Here is an example of how you could create such a plot:
1) Define the matrix M that contains the data. Each column in M represents a different category.
M = randn(100, 3);
2) Create a cell array containing the category names. These names will be used as labels on the x-axis.
categories = {'Category 1', 'Category 2', 'Category 3'};
% Number of categories
numCategories = size(M, 2);
3) Plot each category by using a for loop to iterate over each column of the matrix M.
- Use “jitter” function to avoid overlapping points, generate a small random jitter for the x-axis positions.
- Use the “scatter” function to plot the data points.
for i = 1:numCategories
jitter = (rand(size(M, 1), 1) - 0.5) * 0.2;
scatter(i + jitter, M(:, i), 'filled');
hold on;
end
4) Set X-ticks and X-tick labels.
% Set x-ticks to be at the center of each category
set(gca, 'XTick', 1:numCategories, 'XTickLabel', categories);
xlabel('Categories');
ylabel('Values');
title('Categorized Dot Plot');
% Adjust axis limits for better visualization
xlim([0.5, numCategories + 0.5]);
For more information on the “jitter” and “scatter” functions, please refer to the following documentation:
I hope this answer was helpful.
