Effacer les filtres
Effacer les filtres

How can I plot outliers in their correct position with respect to the original data?

2 vues (au cours des 30 derniers jours)
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?
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

Réponse acceptée

dpb
dpb le 15 Oct 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by