Why is my scatter plot producing inconsistent results?

1 view (last 30 days)
Im trying to make a basic scatter plot from some data that I have collected but my code is producing inconsistent results. I'm only getting 9/10 points to plot for 2017/2018 and the legend is inaccurate for 2017. I dont understand why this is happening because i literally copy and pasted the plot commands and then just changed correspomding year numbers.
clear all; close all;
pd19 = [3650];
pd18 = [3494];
pd17 = [2713];
chr19 = [2480];
chr18 = [2479];
mat17 = [2470];
cai19 = [2365];
cai18 = [2958];
cai17 = [2881];
ev19 = [2955];
ev18 = [2688];
ev17 = [2631];
jen19 = [2862];
jen18 = [2871];
jen17 = [2345];
nad19 = [2546];
nad18 = [2423];
nad17 = [2410];
sch19 = [2771];
sch18 = [2996];
sch17 = [2631];
jam19 = [2307];
jam18 = [2546];
jam17 = [2226];
sea19 = [2915];
sea18 = [3494];
bla17 = [2402];
mar19 = [2603];
mar18 = [2683];
mar17 = [2500];
x19 = [2019];
x18 = [2018];
x17 = [2017];
figure(1)
hold on
scatter(x19,pd19, 'd', 'filled')
scatter(x19, ev19,'d', 'filled')
scatter(x19, chr19,'filled')
scatter(x19, cai19,'d', 'filled')
scatter(x19, mar19, 'filled')
scatter(x19, jen19, 'd', 'filled')
scatter(x19, sea19, 'filled')
scatter(x19, sch19, 'm','d', 'filled')
scatter(x19, jam19, 'filled')
scatter(x19, nad19, 'filled')
xlim([2016 2020])
ylim([2200 3700])
title('League scoring over time')
ylabel('Points For')
xlabel('Year')
grid on
legend('pd', 'evan','chris/matt','caitlyn','mark','jenna','sean/blazic','schiesl','james','nadav')
scatter(x18,pd18, 'd', 'filled')
scatter(x18, ev18,'d', 'filled')
scatter(x18, chr18, 'filled')
scatter(x18, cai18,'d', 'filled')
scatter(x18, mar18, 'filled')
scatter(x18, jen18,'d', 'filled')
scatter(x18, sea18, 'filled')
scatter(x18, sch18,'m','d', 'filled')
scatter(x18, jam18, 'filled')
scatter(x18, nad18, 'filled')
legend('pd', 'evan','chris/matt','caitlyn','mark','jenna','sean/blazic','schiesl','james','nadav')
scatter(x17,pd17, 'd', 'filled')
scatter(x17, ev17,'d', 'filled')
scatter(x17, mat17, 'filled')
scatter(x17, cai17,'d', 'filled')
scatter(x17, mar17, 'filled')
scatter(x17, jen17,'d', 'filled')
scatter(x17, bla17, 'filled')
scatter(x17, sch17,'m','d', 'filled')
scatter(x17, jam17, 'filled')
scatter(x17, nad17, 'filled')
legend('pd', 'evan','chris/matt','caitlyn','mark','jenna','sean/blazic','schiesl','james','nadav')
hold off

Accepted Answer

darova
darova on 21 Feb 2020
I made some changes to your code. Look
points = [pd17 ev17 mat17 cai17 mar17 jen17 bla17 sch17 jam17 nad17
pd18 ev18 chr18 cai18 mar18 jen18 sea18 sch18 jam18 nad18
pd19 ev19 chr19 cai19 mar19 jen19 sea19 sch19 jam19 nad19];
v0 = points(1,:)*0;
year = [v0+x17; v0+x18; v0+x19];
cmap = jet(10);
% plot all data
h = plot(year,points,'.','markersize',20);
% pd, evan, caitlyn, jenna, schiesl - diamond marker
set(h([1 2 4 6 8]),'marker','d','markersize',10)
% choose for every name color
for i = 1:10
set(h(i),'color',cmap(i,:),'markerFaceColor',cmap(i,:))
end
% set schiesl 'magenta' color
set(h(8),'color','m','markerFaceColor','m')
legend('pd', 'evan','chris/matt','caitlyn','mark','jenna','sean/blazic','schiesl','james','nadav')
xlim([2016 2020])
ylim([2200 3700])
title('League scoring over time')
ylabel('Points For')
xlabel('Year')
grid on
Result
I also noticed identical values
% pd18 = [3494];
% sea18 = [3494];

More Answers (1)

Giuseppe Inghilterra
Giuseppe Inghilterra on 21 Feb 2020
Edited: Giuseppe Inghilterra on 21 Feb 2020
Hi,
your code is correct. ev17 and sch17 have the same value (2631). Both are plotted with diamond marker, thus they are superimposed.
I advice you to use a different marker for each scatter plot of same year. In this way a marker identifies a player. Moreover, if you want that legend is accurate in terms of marker and color, you also have to fix color for each scatter plot in order to have same marker and same color for same player.
From here you can get all types of marker that you can use:
Hope this helps.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!