Hello all,
I am working on plotting some data using the Plot commands, and I noticed something interesting. I have been plotting arrays, and been getting confusing results using the setLimits function. My code looks like this: Plot.create("Total Area vs. Slice Number","Slice", "Total Area", totalArea); Plot.setColor("orange"); Plot.setLimits(1, totalArea.length, 0, 50000); Plot.show(); The array has a 0 value at 0 (I wanted the data to correlate with slice number, so the array really starts at 1, hence the 1-totalArea.length for x-values.) and then at 1 it jumps up to about 17000. Now, in the plot, there are several problems: 1. It displays totalArea[1] somewhere around (0, 6000), optically, on the plot. If I hover my mouse over that point though, it says (1, 17250). Interesting.... 2. Despite setting the y-scale to be (0, 50000), the last axis label on the plot only goes up to 15000, so it probably goes up to about 17500. Thanks, Tony Rotella |
From the definition page at
http://rsb.info.nih.gov/ij/developer/macro/functions.html. Plot.setLimits(xMin, xMax, yMin, yMax) Sets the range of the x-axis and y-axis of plots created using Plot.create(). Must be called immediately after Plot.create(). Move Plot.setLimits() after Plot.create(). Also, nothing in your code says 1-totalArea.length. Anyhow, I don't know why you would want the maximum x value of the graph to be the length of the array holding the x values. I would imagine that you want it to be the maximum (or slightly larger than maximum ) value of the values in the x array. Likewise, you want the minimum x value to be the minimum (or sligtly less than minimum) of the values in the x array, which may or may not be anywhere near 1, as you have coded. Having the array index match the slice number is odd. Just use slice_number-1 when you access values in the array. Justin On 8/17/07, Rotella, Anthony M. (GRC)[] <[hidden email]> wrote: > Hello all, > > I am working on plotting some data using the Plot commands, and > I noticed something interesting. I have been plotting arrays, and been > getting confusing results using the setLimits function. My code looks > like this: > > Plot.create("Total Area vs. Slice Number","Slice", "Total Area", > totalArea); > Plot.setColor("orange"); > Plot.setLimits(1, totalArea.length, 0, 50000); > Plot.show(); > > The array has a 0 value at 0 (I wanted the data to correlate with slice > number, so the array really starts at 1, hence the 1-totalArea.length > for x-values.) and then at 1 it jumps up to about 17000. Now, in the > plot, there are several problems: > > 1. It displays totalArea[1] somewhere around (0, 6000), optically, on > the plot. If I hover my mouse over that point though, it says (1, > 17250). Interesting.... > > 2. Despite setting the y-scale to be (0, 50000), the last axis label on > the plot only goes up to 15000, so it probably goes up to about 17500. > > Thanks, > > Tony Rotella > |
If you look at my code, the plot is of an area vs. slice number. That means that the x-values would start at 1, and go till the end of the array, increasing by 1. And it would be nice to start at 0 like normal, but then when you plot them, you would have data at the wrong slice number, since they would start at zero, not 1. I think if you look at my code a second time, this should be clear.
________________________________ From: ImageJ Interest Group on behalf of Justin McGrath Sent: Fri 8/17/2007 9:11 PM To: [hidden email] Subject: Re: Plot bug? From the definition page at http://rsb.info.nih.gov/ij/developer/macro/functions.html. Plot.setLimits(xMin, xMax, yMin, yMax) Sets the range of the x-axis and y-axis of plots created using Plot.create(). Must be called immediately after Plot.create(). Move Plot.setLimits() after Plot.create(). Also, nothing in your code says 1-totalArea.length. Anyhow, I don't know why you would want the maximum x value of the graph to be the length of the array holding the x values. I would imagine that you want it to be the maximum (or slightly larger than maximum ) value of the values in the x array. Likewise, you want the minimum x value to be the minimum (or sligtly less than minimum) of the values in the x array, which may or may not be anywhere near 1, as you have coded. Having the array index match the slice number is odd. Just use slice_number-1 when you access values in the array. Justin On 8/17/07, Rotella, Anthony M. (GRC)[] <[hidden email]> wrote: > Hello all, > > I am working on plotting some data using the Plot commands, and > I noticed something interesting. I have been plotting arrays, and been > getting confusing results using the setLimits function. My code looks > like this: > > Plot.create("Total Area vs. Slice Number","Slice", "Total Area", > totalArea); > Plot.setColor("orange"); > Plot.setLimits(1, totalArea.length, 0, 50000); > Plot.show(); > > The array has a 0 value at 0 (I wanted the data to correlate with slice > number, so the array really starts at 1, hence the 1-totalArea.length > for x-values.) and then at 1 it jumps up to about 17000. Now, in the > plot, there are several problems: > > 1. It displays totalArea[1] somewhere around (0, 6000), optically, on > the plot. If I hover my mouse over that point though, it says (1, > 17250). Interesting.... > > 2. Despite setting the y-scale to be (0, 50000), the last axis label on > the plot only goes up to 15000, so it probably goes up to about 17500. > > Thanks, > > Tony Rotella > |
Ah, I see. Well in that case setting the plot limits will not correct
the problem. In Plot.create() it looks like you only specify the y array, so it uses 0 to yarray.length-1 as the x array. If you just set the x limits from 1 to array.length (without passing the right x array), you'll cut off the first value. You need a pass an array with the right values to Plot.create(). This should work, although there might be an easier way. xarray = newArray(totalArea.length); for ( i = 0 ; i < xarray.length ; i++) { xarray[i] = i+1; } Then you can set your plot limits. Plot.setLimits has to come directly after Plot.create() or the axis labels won't change. Justin On 8/18/07, Rotella, Anthony M. (GRC)[] <[hidden email]> wrote: > If you look at my code, the plot is of an area vs. slice number. That means that the x-values would start at 1, and go till the end of the array, increasing by 1. And it would be nice to start at 0 like normal, but then when you plot them, you would have data at the wrong slice number, since they would start at zero, not 1. I think if you look at my code a second time, this should be clear. > > ________________________________ > > From: ImageJ Interest Group on behalf of Justin McGrath > Sent: Fri 8/17/2007 9:11 PM > To: [hidden email] > Subject: Re: Plot bug? > > > > From the definition page at > http://rsb.info.nih.gov/ij/developer/macro/functions.html. > > Plot.setLimits(xMin, xMax, yMin, yMax) > Sets the range of the x-axis and y-axis of plots created using > Plot.create(). Must be called immediately after Plot.create(). > > Move Plot.setLimits() after Plot.create(). > > Also, nothing in your code says 1-totalArea.length. Anyhow, I don't > know why you would want the maximum x value of the graph to be the > length of the array holding the x values. I would imagine that you > want it to be the maximum (or slightly larger than maximum ) value of > the values in the x array. Likewise, you want the minimum x value to > be the minimum (or sligtly less than minimum) of the values in the x > array, which may or may not be anywhere near 1, as you have coded. > > > Having the array index match the slice number is odd. Just use > slice_number-1 when you access values in the array. > > Justin > > On 8/17/07, Rotella, Anthony M. (GRC)[] <[hidden email]> wrote: > > Hello all, > > > > I am working on plotting some data using the Plot commands, and > > I noticed something interesting. I have been plotting arrays, and been > > getting confusing results using the setLimits function. My code looks > > like this: > > > > Plot.create("Total Area vs. Slice Number","Slice", "Total Area", > > totalArea); > > Plot.setColor("orange"); > > Plot.setLimits(1, totalArea.length, 0, 50000); > > Plot.show(); > > > > The array has a 0 value at 0 (I wanted the data to correlate with slice > > number, so the array really starts at 1, hence the 1-totalArea.length > > for x-values.) and then at 1 it jumps up to about 17000. Now, in the > > plot, there are several problems: > > > > 1. It displays totalArea[1] somewhere around (0, 6000), optically, on > > the plot. If I hover my mouse over that point though, it says (1, > > 17250). Interesting.... > > > > 2. Despite setting the y-scale to be (0, 50000), the last axis label on > > the plot only goes up to 15000, so it probably goes up to about 17500. > > > > Thanks, > > > > Tony Rotella > > > |
Free forum by Nabble | Edit this page |