-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclusterPlot.java
More file actions
76 lines (56 loc) · 2.02 KB
/
Copy pathclusterPlot.java
File metadata and controls
76 lines (56 loc) · 2.02 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.nlptools.corenlp;
import java.awt.Color;
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class clusterPlot extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
String[][]folderTopicArray;
double [][] reducedMatrix;
int []normalizedLabels;
String title;
public clusterPlot(String title, double [][] reducedMatrix, int []normalizedLabels, String[][]folderTopicArray ) {
super(title);
this.title = title;
this.folderTopicArray = folderTopicArray;
this.reducedMatrix = reducedMatrix;
this.normalizedLabels = normalizedLabels;
// Create dataset
XYDataset dataset = createDataset();
// Create chart
JFreeChart chart = ChartFactory.createScatterPlot(
title,
"PC1", "PC2", dataset);
//Changes background color
XYPlot plot = (XYPlot)chart.getPlot();
plot.setBackgroundPaint(new Color(255,228,196));
// Create Panel
ChartPanel panel = new ChartPanel(chart);
setContentPane(panel);
}
private XYDataset createDataset() {
XYSeriesCollection dataset = new XYSeriesCollection();
for(int i = 0; i < folderTopicArray.length; i++) {
String title = "Predicted: ";
for(int k = 0; k < folderTopicArray[0].length; k++) {
title = title + folderTopicArray[i][k] + " ";
}
XYSeries series = new XYSeries(title);
for(int j = 0; j < normalizedLabels.length; j++) {
if(normalizedLabels[j]==i) {
series.add(reducedMatrix[j][0],reducedMatrix[j][1]);
}
}
dataset.addSeries(series);
}
return dataset;
}
}