use of dr.app.gui.chart.LinearAxis in project beast-mcmc by beast-dev.
the class DensityEstimate method calculateFrequencies.
protected FrequencyDistribution calculateFrequencies(Variate data, int minimumBinCount) {
double min = (Double) data.getMin();
double max = (Double) data.getMax();
if (min == max) {
if (min == 0) {
min = -1.0;
} else {
min -= Math.abs(min / 10.0);
}
if (max == 0) {
max = 1.0;
} else {
max += Math.abs(max / 10.0);
}
}
Axis axis = new LinearAxis(Axis.AT_MAJOR_TICK, Axis.AT_MAJOR_TICK);
axis.setRange(min, max);
int majorTickCount = axis.getMajorTickCount();
axis.setPrefNumTicks(majorTickCount, 4);
double binSize = axis.getMinorTickSpacing();
int binCount = (int) ((axis.getMaxAxis() - axis.getMinAxis()) / binSize) + 2;
if (minimumBinCount > 0) {
while (binCount < minimumBinCount) {
majorTickCount++;
axis.setPrefNumTicks(majorTickCount, 4);
binSize = axis.getMinorTickSpacing();
// should +2, otherwise the last bar will lose
binCount = (int) ((axis.getMaxAxis() - axis.getMinAxis()) / binSize) + 2;
}
}
FrequencyDistribution frequency = new FrequencyDistribution(axis.getMinAxis(), binCount, binSize);
for (int i = 0; i < data.getCount(); i++) {
frequency.addValue((Double) data.get(i));
}
return frequency;
}
Aggregations