[r19]: MLPlot / src / indiji / mlplot / demo / Demo1.java Maximize Restore History

Download this file

Demo1.java    45 lines (35 with data), 1.1 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
package indiji.mlplot.demo;
import indiji.mlplot.MLPlot;
import indiji.mlplot.MLPlot.Style;
import indiji.mlplot.MLPlot.Symbol;
import java.io.File;
public class Demo1 {
public static void main(String[] args){
// Create data
double x[]=new double[100];
double y_sine[]=new double[100];
double y_cosine[]=new double[100];
double y_rand[]=new double[100];
for(int n=0;n<x.length;n++){
x[n]=2*Math.PI*n/x.length;
y_sine[n]=Math.sin(x[n]);
y_cosine[n]=Math.cos(x[n]);
y_rand[n]=2*Math.random()-1;
}
// Create a new Plot
MLPlot p=new MLPlot();
// Draw data
p.linePlot(x,y_sine,"black",Style.Solid,Symbol.Star,"Sine");
p.linePlot(x,y_cosine,"red",Style.Dotted,Symbol.TriangleUpFilled,"Cosine");
p.linePlot(x,y_rand,"blue",Style.Dashed,Symbol.Circle,"Random");
// Customize Plot
p.setTitle("Hello World");
p.setLegendPos("NE");
p.setxTicks(new double[]{0,Math.PI,2*Math.PI});
p.setxTickLabels(new String[]{"0","π","2π"});
// Save Vector/Bitmap Graphics
p.save(new File("demo1.svg"));
p.save(new File("demo1.jpg"),800);
p.save(new File("demo1.eps"));
}
}