How can I plot outliers in their correct position with respect to the original data?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Seyed Navid Shoaiby
am 15 Okt. 2022
Beantwortet: dpb
am 15 Okt. 2022
This plotting does not show the outliers in correct order. I want to plot the original data, and then mark the outliers in their correct order. The resulting graph is this. I want the red points in line with other data points. Any suggestions?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1157463/image.bmp)
Temp = data(:,2); % Separating the feature vector
Temp_z_score = (Temp - mean(Temp)) / std(Temp); % Calculation of the z-score (z-score = the number of standard deviations a point is below or over the mean)
threshold = abs(Temp_z_score)>1.8; % Setting the outliers threshold
figure
plot(Temp(~threshold),'bo','DisplayName','Temperature')
hold on
plot(Temp(threshold),'r*','DisplayName','Outlier')
hold off
grid on
0 Kommentare
Akzeptierte Antwort
dpb
am 15 Okt. 2022
You're just plotting the selected array elements against their ordinal number; you need a corollary x value against which to plot them...one could assume that would be the first column in the data array...
z_score=zscore(data(:,2));
isOut=abs(z_score)>1.8;
figure
plot(data(~isOut,1),data(~isOut,2),'bo','DisplayName','Temperature')
hold on
plot(data(isOut,1),data(isOut,2),'r*','DisplayName','Outlier')
hold off
grid on
If the actual x values aren't the first column after all, then use
plot(find(~isOut),data(~isOut,2),'bo','DisplayName','Temperature')
hold on
plot(find(isOut),data(isOut,2),'r*','DisplayName','Outlier')
instead to return the locations in the original vector
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!