Issue within the plot class

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue within the plot class

CARL Philippe (LBP)
Dear all (probably mostly Michael)
I have the following java code:
plot = new Plot("Title", "x_label", "y_ label ");
for(i = 0; i != 15; i++)
{
get_new_x_and_y_values();
plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(i));
}
plot.show();
And knowing that the x values generated by the method get_new_x_and_y_values() are identical through each iteration, I would have expected to get the following columns list within the plot list table:
x_label 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
but instead I get the following columns
x_label 0 1 2 3 4 5 X_6 6 7 8 9 10 X_11 11 12 13 14
with the content of the columns x_label, X_6 and X_11 being similar.
Thus, am I doing something wrong or is there a way to solve this issue?
I thank you very much in advance for your lighting on this.
My best regards,
Philippe







Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Issue within the plot class

Michael Schmid-3
Hi Philippe,

sorry, I have no idea what could be wrong.
In the list (ResultsTable) created by a Plot, a new x column is inserted
only if the x data are not exactly the same as in the first PlotObject
with x,y data, or if there are data sets with different size.
You can find the code here:
https://github.com/imagej/imagej1/blob/master/ij/gui/Plot.java#L3482
Comparison is done by the Java Arrays.equals method.

I tried with a sample macro; no such problem:

   n = 50;
   types =  newArray("Line", "Connected Circle", "Filled", "Bar",
"Separated Bar",
     "Circle", "Box", "Triangle", "Diamond", "Cross", "X", "Dot");
   setBatchMode(true);
   newImage("", "32-bit noise", n, 1, 1);
   run("Gaussian Blur...", "sigma=3");
   List.setMeasurements;
   min = List.getValue("Min");
   max = List.getValue("Max");
   value = -min;
   run("Add...", "value=&value");
   run("Select All");
   yPoints = getProfile();
   close;
   setBatchMode(false);
   xPoints=Array.getSequence(n);
   Plot.create("Plot Test", "X", "Y");
   for (i=1; i<=15; i++) {
     label=toString(i);
     Plot.add("line", xPoints, yPoints, label);
     for (p=0; p<n;p++) yPoints[p]+=0.1;
   }
   Plot.show();

I get the following header for the table created by 'List':
X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


Michael
_____________________________________________________________________

On 26/08/2019 2:38 PM, CARL Philippe (LBP) wrote:

> Dear all (probably mostly Michael)
> I have the following java code:
> plot = new Plot("Title", "x_label", "y_ label ");
> for(i = 0; i != 15; i++)
> {
> get_new_x_and_y_values();
> plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(i));
> }
> plot.show();
> And knowing that the x values generated by the method get_new_x_and_y_values() are identical through each iteration, I would have expected to get the following columns list within the plot list table:
> x_label 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> but instead I get the following columns
> x_label 0 1 2 3 4 5 X_6 6 7 8 9 10 X_11 11 12 13 14
> with the content of the columns x_label, X_6 and X_11 being similar.
> Thus, am I doing something wrong or is there a way to solve this issue?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Issue within the plot class

Kenneth Sloan-3
In reply to this post by CARL Philippe (LBP)
My first thought is to wonder if you get an "X_16" column when you extend
the number of iterations to 20.  If you do, this might provide a clue.

Second - x,y, and i are all global to this code snippet.  Is it possible that
"get_new_x_and_y_values()" modifies i (as well as, I presume, x and y)?

Just to be sure, I would print the value of "i" immediately
before/after the call to "get_new_x_and_y_values()".

I'm also not entirely happy with the termination condition in the for statement.
It's not a substantive objection - just style.

I'm assuming that "i" is actually used inside "get_new_x_and_y_values()", so

Adding this all up, I would re-write as:

for(int j=0;j<20;j++)
{
        i = j;
        IJ.log("before: i, j = " + i + ", " + j);
        get_new_x_and_y_values();
        IJ.log("after : i, j = " + i + ", " + j);
        plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(j);
}

and then perhaps a few variants - reverting step-by-step to the original.

I must admit that I can't think of any place *other than* the code for Plot that would generate the "X_" column headings.
But, I would run the above tests first, just to be absolutely sure.

Questions:
 a) where (and how) is "i" declared?  Are you *sure* it is an int?
 b) is "i" used in "get_new_x_and_y_values()"?  if so, is it modified?

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Aug 26, 2019, at 07:38, CARL Philippe (LBP) <[hidden email]> wrote:
>
> Dear all (probably mostly Michael)
> I have the following java code:
> plot = new Plot("Title", "x_label", "y_ label ");
> for(i = 0; i != 15; i++)
> {
> get_new_x_and_y_values();
> plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(i));
> }
> plot.show();
> And knowing that the x values generated by the method get_new_x_and_y_values() are identical through each iteration, I would have expected to get the following columns list within the plot list table:
> x_label 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> but instead I get the following columns
> x_label 0 1 2 3 4 5 X_6 6 7 8 9 10 X_11 11 12 13 14
> with the content of the columns x_label, X_6 and X_11 being similar.
> Thus, am I doing something wrong or is there a way to solve this issue?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe
>
>
>
>
>
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

ImageJ Documentation Wiki

Fred Damen
Greetings,

"ImageJ Documentation Wiki" currently appears to be nonexistent, no current
name server entry.  Does anyone know its status and/or future?

Thanks,

Fred

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ Documentation Wiki

Wayne Rasband-2
> On Aug 26, 2019, at 3:50 PM, Fred Damen <[hidden email]> wrote:
>
> Greetings,
>
> "ImageJ Documentation Wiki" currently appears to be nonexistent, no current
> name server entry.  Does anyone know its status and/or future?


The ImageJ Documentation Wiki is now at

  https://imagejdocu.list.lu/

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Issue within the plot class

CARL Philippe (LBP)
In reply to this post by Michael Schmid-3
Dear Michael,
My imputations were indeed wrong and I'm really sorry about that!!!
Indeed, when I compare the output of the x values they are indeed sometimes different and this after the 6th decimal value which explains the addition of this new x column.
Thanks for your help and have a nice (which I guess sunny) day!
Kindest regards,
Philippe

----- Mail original -----
De: "Michael Schmid" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 26 Août 2019 18:08:35
Objet: Re: Issue within the plot class

Hi Philippe,

sorry, I have no idea what could be wrong.
In the list (ResultsTable) created by a Plot, a new x column is inserted
only if the x data are not exactly the same as in the first PlotObject
with x,y data, or if there are data sets with different size.
You can find the code here:
https://github.com/imagej/imagej1/blob/master/ij/gui/Plot.java#L3482
Comparison is done by the Java Arrays.equals method.

I tried with a sample macro; no such problem:

   n = 50;
   types =  newArray("Line", "Connected Circle", "Filled", "Bar",
"Separated Bar",
     "Circle", "Box", "Triangle", "Diamond", "Cross", "X", "Dot");
   setBatchMode(true);
   newImage("", "32-bit noise", n, 1, 1);
   run("Gaussian Blur...", "sigma=3");
   List.setMeasurements;
   min = List.getValue("Min");
   max = List.getValue("Max");
   value = -min;
   run("Add...", "value=&value");
   run("Select All");
   yPoints = getProfile();
   close;
   setBatchMode(false);
   xPoints=Array.getSequence(n);
   Plot.create("Plot Test", "X", "Y");
   for (i=1; i<=15; i++) {
     label=toString(i);
     Plot.add("line", xPoints, yPoints, label);
     for (p=0; p<n;p++) yPoints[p]+=0.1;
   }
   Plot.show();

I get the following header for the table created by 'List':
X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


Michael
_____________________________________________________________________

On 26/08/2019 2:38 PM, CARL Philippe (LBP) wrote:

> Dear all (probably mostly Michael)
> I have the following java code:
> plot = new Plot("Title", "x_label", "y_ label ");
> for(i = 0; i != 15; i++)
> {
> get_new_x_and_y_values();
> plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(i));
> }
> plot.show();
> And knowing that the x values generated by the method get_new_x_and_y_values() are identical through each iteration, I would have expected to get the following columns list within the plot list table:
> x_label 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> but instead I get the following columns
> x_label 0 1 2 3 4 5 X_6 6 7 8 9 10 X_11 11 12 13 14
> with the content of the columns x_label, X_6 and X_11 being similar.
> Thus, am I doing something wrong or is there a way to solve this issue?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Issue within the plot class

CARL Philippe (LBP)
In reply to this post by Kenneth Sloan-3
Dear Kenneth,
Thanks a lot for your error suggestions and I completely agree with you that int parameters like i, j, k,... that we all use in loops can often be unexpectedly changed, at least more than we would wish (or remember).
Thus in order to limit such errors, I always redefine the needed local iterators in each function (void, String, double,...) where they are needed in order to try to limit such issues.
My best regards,
Philippe

----- Mail original -----
De: "Kenneth Sloan" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 26 Août 2019 19:00:49
Objet: Re: Issue within the plot class

My first thought is to wonder if you get an "X_16" column when you extend
the number of iterations to 20.  If you do, this might provide a clue.

Second - x,y, and i are all global to this code snippet.  Is it possible that
"get_new_x_and_y_values()" modifies i (as well as, I presume, x and y)?

Just to be sure, I would print the value of "i" immediately
before/after the call to "get_new_x_and_y_values()".

I'm also not entirely happy with the termination condition in the for statement.
It's not a substantive objection - just style.

I'm assuming that "i" is actually used inside "get_new_x_and_y_values()", so

Adding this all up, I would re-write as:

for(int j=0;j<20;j++)
{
        i = j;
        IJ.log("before: i, j = " + i + ", " + j);
        get_new_x_and_y_values();
        IJ.log("after : i, j = " + i + ", " + j);
        plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(j);
}

and then perhaps a few variants - reverting step-by-step to the original.

I must admit that I can't think of any place *other than* the code for Plot that would generate the "X_" column headings.
But, I would run the above tests first, just to be absolutely sure.

Questions:
 a) where (and how) is "i" declared?  Are you *sure* it is an int?
 b) is "i" used in "get_new_x_and_y_values()"?  if so, is it modified?

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Aug 26, 2019, at 07:38, CARL Philippe (LBP) <[hidden email]> wrote:
>
> Dear all (probably mostly Michael)
> I have the following java code:
> plot = new Plot("Title", "x_label", "y_ label ");
> for(i = 0; i != 15; i++)
> {
> get_new_x_and_y_values();
> plot.addPoints(x, y, null, Plot.CIRCLE, String.valueOf(i));
> }
> plot.show();
> And knowing that the x values generated by the method get_new_x_and_y_values() are identical through each iteration, I would have expected to get the following columns list within the plot list table:
> x_label 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
> but instead I get the following columns
> x_label 0 1 2 3 4 5 X_6 6 7 8 9 10 X_11 11 12 13 14
> with the content of the columns x_label, X_6 and X_11 being similar.
> Thus, am I doing something wrong or is there a way to solve this issue?
> I thank you very much in advance for your lighting on this.
> My best regards,
> Philippe
>
>
>
>
>
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html