erdogant / pca

pca: A Python Package for Principal Component Analysis.
https://erdogant.github.io/pca
MIT License
286 stars 43 forks source link

how to plot part of data by function model.scatter() #22

Closed weiping2020 closed 2 years ago

weiping2020 commented 2 years ago

hi,

Thanks for your python library, I am using the library for PCA.

But have a question, for the function model.scatter()

model.scatter(SPE=True, hotellingt2=True,legend=False , label=None, cmap='Set1', ='#ffffff' )

the data has 2000 lines, can we just plot the data from line 1000 to line 2000?

Or other dataset?

Thanks a lot.

Willa.

erdogant commented 2 years ago

There are some solutions to do this. The output of the scatter function contains fig and ax that you can use to make desired manipulations in the graph.

fig, ax = model.scatter()
# Plot the new samples on top of the existing space
ax.scatter(x, y, marker='x', s=200)

Alternatively, you can also manipulate the results that are stored in the object itself.

As an example:

model.results['PC'] = model.results['PC'].iloc[1000:2000 :]
model.results['outliers']=model.results['outliers'].iloc[1000:2000,:]
# Make plot
fig, ax = model.scatter(SPE=True, hotellingt2=True,legend=False ,
label=None, cmap='Set1',  gradient='#ffffff')

Note that the plot with the oval outlier circle will be different compared to when you have all samples in the model because it is built on the availability of the points.