-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScatterPlot.java
More file actions
48 lines (42 loc) · 1.28 KB
/
ScatterPlot.java
File metadata and controls
48 lines (42 loc) · 1.28 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
package at.alepfu;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.spark.mllib.linalg.Vector;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class ScatterPlot {
private XYSeriesCollection dataset;
private JFreeChart chart;
public ScatterPlot(List<List<Vector>> clusters) {
this.dataset = new XYSeriesCollection();
int i = 0;
for (List<Vector> cluster : clusters) {
XYSeries series = new XYSeries(i++);
for (Vector p : cluster)
series.add(p.toArray()[0], p.toArray()[1]);
this.dataset.addSeries(series);
}
this.chart = ChartFactory.createScatterPlot("Average ratings", "track", "album",
this.dataset, PlotOrientation.VERTICAL, false, false, false);
}
public void show() {
ChartFrame frame = new ChartFrame("", this.chart);
frame.pack();
frame.setVisible(true);
}
public void save(String filename) {
int width = 660;
int height = 420;
try {
ChartUtilities.saveChartAsJPEG(new File(filename), this.chart, width, height);
} catch (IOException e) {
e.printStackTrace();
}
}
}