add logarithmic scaling for the y-axis
Often we have a few very high values and a lot low values. With a linearly scaled y-axis the plot is mostly useless.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
public enum AxisScale {
|
||||
LINEAR, LOG10, LOG2
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public class PlotSettings {
|
||||
|
||||
private String dateRange;
|
||||
|
||||
private AxisScale yAxisScale;
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
@@ -142,11 +144,18 @@ public class PlotSettings {
|
||||
}
|
||||
}
|
||||
|
||||
public void setYAxisScale(final AxisScale axisScale) {
|
||||
this.yAxisScale = axisScale;
|
||||
}
|
||||
|
||||
public AxisScale getYAxisScale() {
|
||||
return yAxisScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", groupBy=" + groupBy
|
||||
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
|
||||
+ "]";
|
||||
+ ", axisScale=" + yAxisScale + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.lucares.recommind.logs;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.lucares.pdb.plot.api.AxisScale;
|
||||
|
||||
public class GnuplotFileGenerator {
|
||||
|
||||
public String generate(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
@@ -20,6 +22,11 @@ public class GnuplotFileGenerator {
|
||||
appendfln(result, "set xtics rotate by %d", settings.getRotateXAxisLabel());
|
||||
|
||||
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
||||
if (settings.getYAxisScale() == AxisScale.LOG10) {
|
||||
appendfln(result, "set logscale y");
|
||||
} else if (settings.getYAxisScale() == AxisScale.LOG2) {
|
||||
appendfln(result, "set logscale y 2");
|
||||
}
|
||||
|
||||
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath().toString().replace("\\", "/"));
|
||||
appendf(result, "plot ");
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.lucares.recommind.logs;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.lucares.pdb.plot.api.AxisScale;
|
||||
|
||||
public class GnuplotSettings {
|
||||
private String terminal = "png";
|
||||
private int height = 1200;
|
||||
@@ -25,6 +27,7 @@ public class GnuplotSettings {
|
||||
|
||||
// set xtics rotate by 80
|
||||
private int rotateXAxisLabel = -80;
|
||||
private AxisScale yAxisScale;
|
||||
|
||||
public GnuplotSettings(final Path output) {
|
||||
this.output = output;
|
||||
@@ -106,6 +109,14 @@ public class GnuplotSettings {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setYAxisScale(final AxisScale yAxisScale) {
|
||||
this.yAxisScale = yAxisScale;
|
||||
}
|
||||
|
||||
public AxisScale getYAxisScale() {
|
||||
return yAxisScale;
|
||||
}
|
||||
|
||||
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
||||
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ public class Plotter {
|
||||
gnuplotSettings.setHeight(height);
|
||||
gnuplotSettings.setWidth(width);
|
||||
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
||||
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||
|
||||
return new PlotResult(outputFile.getFileName(), dataSeries);
|
||||
|
||||
Reference in New Issue
Block a user