# Make a scatter plot bigger and ad legend, axis

2 views (last 30 days)
Joel Schelander on 23 Apr 2021
Answered: Abhishek Chakram on 11 Oct 2023
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
xx=cell(length(AAG{y}),1);
I=cell(length(AAG{y}),1);
for o=1:length(AAG{y})
xx{o} =AAG{y}{o};
I{o}=AAI{y}(o);
end
for k1 = 1:length(AAG{y})
scatter(ones(1,numel(xx{k1}))*y, xx{k1},ones(1,numel(xx{k1}))*I{k1})
end
end
xlim([0 3])
hold off

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;
xlabel('X');
ylabel('Y');
title('Scatter Plot with Different Colors');
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

### Categories

Find more on Legend in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!