Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scprep.plot.graph() #89

Open
dburkhardt opened this issue Oct 12, 2019 · 0 comments
Open

scprep.plot.graph() #89

dburkhardt opened this issue Oct 12, 2019 · 0 comments

Comments

@dburkhardt
Copy link
Member

dburkhardt commented Oct 12, 2019

import scprep as scprep
import graphtools as gt
import pygsp
import numpy as np

from sklearn import datasets
data = datasets.make_blobs(n_samples=n_samples, random_state=8)

G = gt.Graph(data)

ax = scprep.plot.scatter2d(data, c=group, 
                      xlabel='x0', ylabel='x1',
                      title='blobs_regular', figsize=(6,6),
                     legend=False)

kernel = G.K.toarray()
# This block of code draws lines between each point and its k-nearest neighbors
for i, pt in enumerate(data):
    neighbors = np.where(kernel[i] > 0)[0]
    for j in neighbors:
        if i >= j:
            continue
        nn_coordinates = data[j]
        ax.plot([pt[0], nn_coordinates[0]], [pt[1], nn_coordinates[1]],
               color='k', alpha=kernel[i,j], zorder=0)
    
ax.set_aspect(1)

produces

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants