Commit a74f1731 authored by Rui Vieira's avatar Rui Vieira

Add LinePlot and marker size

parent adc34616
package org.ruivieira.plotlib;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public abstract class AbstractPlot implements Plot {
public abstract class AbstractPlot<T, U> implements Plot {
protected final List<String> xs;
protected final List<String> ys;
protected Optional<String> colour = Optional.empty();
protected Optional<Double> alpha = Optional.empty();
......@@ -10,6 +16,12 @@ public abstract class AbstractPlot implements Plot {
protected final StringBuilder script = new StringBuilder();
public AbstractPlot(Collection<T> x, Collection<U> y) {
this.xs = new Converter<>(x).getConverted();
this.ys = new Converter<>(y).getConverted();
}
public AbstractPlot setColour(String colour) {
this.colour = Optional.of(colour);
return this;
......
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.AbstractPlot;
import org.ruivieira.plotlib.Converter;
import org.ruivieira.plotlib.Plot;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class InterpolationPlot<T, U> extends AbstractPlot implements Plot {
public class InterpolationPlot<T, U> extends AbstractPlot<T, U> implements Plot {
List<String> xs;
List<String> ys;
int steps;
private Optional<String> linestyle = Optional.empty();
public InterpolationPlot(Collection<T> x, Collection<U> y, int steps) {
this.xs = new Converter<>(x).getConverted();
this.ys = new Converter<>(y).getConverted();
super(x, y);
this.steps = steps;
}
public InterpolationPlot setLineStyle(String style) {
this.linestyle = Optional.of(style);
return this;
}
@Override
public String render() {
script.append("from scipy.interpolate import interp1d\n");
......@@ -30,13 +33,12 @@ public class InterpolationPlot<T, U> extends AbstractPlot implements Plot {
renderColour();
renderAlpha();
linestyle.ifPresent(s -> script.append(", linestyle='").append(s).append("'"));
script.append(")\n");
renderYLim();
System.out.println(script.toString());
return script.toString();
}
}
package org.ruivieira.plotlib.plots;
import org.ruivieira.plotlib.AbstractPlot;
import org.ruivieira.plotlib.Plot;
import java.util.Collection;
import java.util.Optional;
public class LinePlot<T, U> extends AbstractPlot<T, U> implements Plot {
private Optional<String> marker = Optional.empty();
private Optional<String> linestyle = Optional.empty();
public LinePlot(Collection x, Collection y) {
super(x, y);
}
public LinePlot setMarker(String marker) {
this.marker = Optional.of(marker);
return this;
}
public LinePlot setLineStyle(String style) {
this.linestyle = Optional.of(style);
return this;
}
@Override
public String render() {
script.append("plt.scatter([").append(String.join(",", xs));
script.append("], [");
script.append(String.join(",", ys));
script.append("]");
marker.ifPresent(s -> script.append(", marker='").append(s).append("'"));
linestyle.ifPresent(s -> script.append(", linestyle='").append(s).append("'"));
renderColour();
renderAlpha();
script.append(")\n");
renderYLim();
return script.toString();
}
}
......@@ -8,19 +8,13 @@ import java.util.Collection;
import java.util.List;
import java.util.Optional;
public class ScatterPlot<T, U> extends AbstractPlot implements Plot {
final List<String> xs;
final List<String> ys;
public class ScatterPlot<T, U> extends AbstractPlot<T, U> implements Plot {
private Optional<String> marker = Optional.empty();
private Optional<String> colour = Optional.empty();
private Optional<Double> markerSize = Optional.empty();
public ScatterPlot(Collection<T> x, Collection<U> y) {
this.xs = new Converter<>(x).getConverted();
this.ys = new Converter<>(y).getConverted();
super(x, y);
}
public ScatterPlot setMarker(String marker) {
......@@ -28,13 +22,20 @@ public class ScatterPlot<T, U> extends AbstractPlot implements Plot {
return this;
}
public ScatterPlot setMarkerSize(double size) {
this.markerSize = Optional.of(size);
return this;
}
@Override
public String render() {
script.append("plt.scatter([").append(String.join(",", xs));
script.append("], [");
script.append(String.join(",", ys));
script.append("]");
marker.ifPresent(s -> script.append(", marker='").append(s).append("'"));
markerSize.ifPresent(s -> script.append(", s=").append(s));
renderColour();
renderAlpha();
......@@ -43,7 +44,6 @@ public class ScatterPlot<T, U> extends AbstractPlot implements Plot {
renderYLim();
System.out.println(script.toString());
return script.toString();
}
......
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