File size: 1,206 Bytes
1ad4e76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Grid } from "@mui/material";
import Plot from "react-plotly.js";

export default function ScatterPlot({ words, x, y }) {
  const colors = [
    "red",
    "blue",
    "green",
    "orange",
    "purple",
    "brown",
    "pink",
    "grey",
    "yellow",
    "cyan",
  ];
  return (
    <>
      <Grid item xs={12}>
        <Plot
          data={words.map((word, index) => {
            const color = colors[index % colors.length];
            return {
              x: [word.embedding[x]],
              y: [word.embedding[y]],
              type: "scatter",
              mode: "markers",
              line: {
                width: 6,
              },
              marker: {
                size: 10,
                color: color,
              },
              name: word.item,
            };
          })}
          layout={{
            title: "Dimensional Plot",
            xaxis: { title: "Dimension " + x, range: [-1, 1] },
            yaxis: { title: "Dimension " + y, range: [-1, 1] },
            showlegend: true,
            autosize: true,
          }}
          useResizeHandler={true}
          style={{ width: "100%", height: "100%" }}
        />
      </Grid>
    </>
  );
}