-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_tsne.py
More file actions
54 lines (43 loc) · 1.73 KB
/
Copy pathplot_tsne.py
File metadata and controls
54 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Using dataframe generated in clustering.py, plot unsupervised clusters."""
from absl import app
from absl import flags
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
FLAGS = flags.FLAGS
flags.DEFINE_string("file", "data/psc_tsne.csv", "Name of file to read.")
flags.DEFINE_string("target", "efficiency", "Name of target value to plot.")
flags.DEFINE_integer('font_size', 18, 'font size to use in labels')
flags.DEFINE_integer('tick_size', 16, 'font size to use in labels')
def main(argv):
df = pd.read_csv(FLAGS.file, index_col=0)
df = df.reindex(range(len(df)))
print("Num rows: ", len(df))
cols_print = [
"electron_transport_layer", "hole_transport_layer",
"back_contact", "substrate", "absorber_fabrication",
"chemical_formula_descriptive", "efficiency", "efficiency_std", "band_gap"]
def on_pick(event):
artist = event.artist
ind = event.ind
print("Points selected: ", len(ind))
for i in ind:
print(df[cols_print].iloc[i])
fig, ax = plt.subplots()
tolerance = 1 # points
cmap = mpl.cm.plasma
#sns.scatterplot(df, x="tsne_0", y="tsne_1", hue=FLAGS.target, palette=cmap,
# ax=ax, picker=tolerance)
cs = ax.scatter(df["tsne_0"], df["tsne_1"], c=df[FLAGS.target], picker=tolerance)
fig.canvas.callbacks.connect('pick_event', on_pick)
cbar = fig.colorbar(cs)
ax.tick_params(which='both', labelsize=FLAGS.tick_size)
ax.set_xlabel("TSNE X", fontsize=FLAGS.font_size)
ax.set_ylabel("TSNE Y", fontsize=FLAGS.font_size)
cbar.ax.set_ylabel(FLAGS.target, fontsize=FLAGS.font_size)
plt.tight_layout()
plt.show()
if __name__ == '__main__':
app.run(main)