Clear Filters
Clear Filters

Make a scatter plot bigger and ad legend, axis

2 views (last 30 days)
I have the following scatter plot, created from for loops. I want to make every staple as thick as possible, like so staple 1 and 2 are in contact with a contour seperating them. I also want a legend telling what the colors represent.. But I do not know how to make one
hold on
for y=1:2
for o=1:length(AAG{y})
xx{o} =AAG{y}{o};
for k1 = 1:length(AAG{y})
scatter(ones(1,numel(xx{k1}))*y, xx{k1},ones(1,numel(xx{k1}))*I{k1})
xlim([0 3])
hold off

Answers (1)

Abhishek Chakram
Abhishek Chakram on 11 Oct 2023
Hi Joel Schelander,
It is my understanding that you want to make the scatter plot bigger and add legend to it. To achieve this, you can resize the “figure” to have the desired height and width using “Position” parameter. For adding the legends, you can use “legend” function. Here is a sample code for the same:
% Generate random data
x1 = rand(1, 100);
y1 = rand(1, 100);
x2 = rand(1, 100);
y2 = rand(1, 100);
x3 = rand(1, 100);
y3 = rand (1, 100);
figure ('Position', [100, 100, 800, 600]);
% Adjust the width and height as needed
% 3rd parameter is the width of the figure
% 4th parameter is the height of the figure
hold on;
scatter(x1, y1, 50, 'red', 'filled');
scatter(x2, y2, 50, 'green', 'filled');
scatter(x3, y3, 50, 'blue', 'filled');
hold off;
title('Scatter Plot with Different Colors');
% Add legend
legend('Array 1', 'Array 2', 'Array 3');
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!