Commit fb296d44 authored by Rui Vieira's avatar Rui Vieira

Initial commit

parent 28f53aa2
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ruivieira</groupId>
<artifactId>java-plotlib</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package org.ruivieira.plotlib;
public class Figure {
public StringBuilder script = new StringBuilder();
public Figure() {
script.append("import matplotlib\nimport matplotlib.pyplot as plt\n\n");
}
public void add(Plot plot) {
script.append(plot.render());
}
public void save() {
System.out.println(script.toString());
}
}
package org.ruivieira.plotlib;
public interface Plot {
String render();
}
package org.ruivieira.plotlib;
import java.util.ArrayList;
import java.util.List;
public class ScatterPlot implements Plot {
List<String> xs = new ArrayList<>();
List<String> ys = new ArrayList<>();
public ScatterPlot() {
}
public String render() {
return "plt.plot([" + String.join(",", xs) + "], [" + String.join(",", ys) + "])\n";
}
public static ScatterPlot create(int[] x, int[] y) {
List<String> xs = new ArrayList<>();
for (int _x : x) {
xs.add(String.valueOf(_x));
}
List<String> ys = new ArrayList<>();
for (int _y : y) {
ys.add(String.valueOf(_y));
}
ScatterPlot plot = new ScatterPlot();
plot.xs = xs;
plot.ys = ys;
return plot;
}
}
package org.ruivieira.plotlib;
public class Test {
public static void main(String[] args) {
Figure figure = new Figure();
int[] x = new int[]{1, 2, 3, 4};
int[] y = new int[]{7, 9, 5, 6};
figure.add(ScatterPlot.create(x, y));
figure.save();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment