erdogant / pca

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

Optionally suppress the center-annotations in scatter plots #47

Closed normanius closed 11 months ago

normanius commented 1 year ago

When creating scatter plots (using scatterd), labels are plotted at the center of mass for each point cloud, see below.

Is it possible to optionally suppress those labels? A couple of reasons for this:

image

I noticed around L656 in pca.py that the labels are extracted from the available arguments. But it appears not to be possible to disable the creation of these annotations.

The Rolls-Royce improvement would be, to optionally include those cloud-mass-annotations when placing texts with "adjustText". But again, adding a switch to disable these cloud-annotations would be nice!

erdogant commented 1 year ago

My idea was to "disable" or remove the text by setting the font size to 0. Maybe this feels more like a hack.

# Load pca
import pandas as pd
from sklearn.datasets import load_iris
from pca import pca

# Load dataset
label = load_iris().feature_names
y = load_iris().target
X = pd.DataFrame(data=load_iris().data, columns=label, index=y)

# Initialize to reduce the data up to the nubmer of componentes that explains 95% of the variance.
model = pca(n_components=3)
# Fit transform
results = model.fit_transform(X)

# Remove text in scatter
fig, ax = model.biplot(fontsize=0)
# Remove text in arrow
fig, ax = model.biplot(arrowdict={'fontsize': 0})
# Remove both
fig, ax = model.biplot(fontsize=0, arrowdict={'fontsize': 0})

# 2D plot
fig, ax = model.scatter(fontsize=0)
fig, ax = model.scatter3d(fontsize=0)
fig, ax = model.biplot3d(fontsize=0)
normanius commented 1 year ago

Okay, that's also a possibility. Make it shrink until it's not visible anymore 😆

Having it in the function API would be maybe a bit cleaner, but for me that's okay so far. Thanks!

erdogant commented 11 months ago

I am closing this one as the issue is fixed :)