Update Plot window
Posted by Michael Doube on Aug 18, 2009; 4:36pm
URL: http://imagej.273.s1.nabble.com/Update-Plot-window-tp3691438.html
Hi all
I have a plugin that iterates in a while loop until convergence occurs
and I'd like to monitor the values graphically. I can draw a Plot of
the values once the while loop has finished, but if I try to redraw the
plot with multiple calls to my graphResults() method I get a rather
large number of Plot windows.
How can I update a plot window with new data? I'm collecting the Y data
in a Vector (because I can add values to it in the while loop). My
plotting method is as follows:
private void graphResults(Vector<Double> anisotropyHistory){
double[] yVariables = new double[anisotropyHistory.size()];
double[] xVariables = new double[anisotropyHistory.size()];
Enumeration<Double> e = anisotropyHistory.elements();
int i = 0;
while (e.hasMoreElements()){
yVariables[i] = e.nextElement();
xVariables[i] = (double)i;
i++;
}
Plot plot = new Plot("Anisotropy", "Number of repeats", "Anisotropy",
xVariables, yVariables);
plot.addPoints(xVariables, yVariables, Plot.X);
plot.setLimits(0, anisotropyHistory.size(), 0, 1);
plot.show();
}
Michael