Ignoring points in a plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ignoring points in a plot

mona_c
This post was updated on .
Is it possible to ignore certain points when plotting a line plot? The following code is from plot example in Fiji. The bold line is changed, however it does not work I get: expected double[] y2 = { 18, Double.[], 3, 1, 7, 11, 11, 5, 2 };
Changing it to Double.NaN also doesn't work correctly, since it goes to -inf.
import ij.gui.Plot;
import ij.gui.PlotWindow;

import ij.plugin.PlugIn;

import java.awt.Color;

/**
 * An example how to use ImageJ's Plot class
 */
public class Plot_Example implements PlugIn {
        /**
         * This method gets called by ImageJ / Fiji.
         *
         * @param arg can be specified in plugins.config
         * @see ij.plugin.PlugIn#run(java.lang.String)
         */
        @Override
        public void run(String arg) {
                // Some data to show
                double[] x = { 1, 3, 4, 5, 6, 7, 8, 9, 11 };
                double[] y = { 20, 5, -2, 3, 10, 12, 8, 3, 0 };
                double[] y2 = { 18, null, 3, 1, 7, 11, 11, 5, 2 };
                double[] x3 = { 2, 10 };
                double[] y3 = { 13, 3 };

                // Initialize the plot with x/y
                Plot plot = new Plot("Example plot", "x", "y", x, y);

                // make some margin (xMin, xMax, yMin, yMax)
                plot.setLimits(0, 12, -3, 21);

                // Add x/y2 in blue; need to draw the previous data first
                plot.draw();
                plot.setColor(Color.BLUE);
                plot.addPoints(x, y2, Plot.LINE);

                // Add x3/y3 as circles instead of connected lines
                plot.draw();
                plot.setColor(Color.BLACK);
                plot.addPoints(x3, y3, Plot.CIRCLE);

                // Finally show it, but remember the window
                PlotWindow window = plot.show();

                // Wait 5 seconds
                try { Thread.sleep(5000); } catch (InterruptedException e) {}

                // Make a new plot and update the window
                plot = new Plot("Example plot2", "x", "y", x, y2);
                plot.setLimits(0, 12, -3, 21);
                plot.draw();
                plot.setColor(Color.GREEN);
                plot.addPoints(x, y, Plot.CROSS);
                plot.draw();
                plot.setColor(Color.RED);
                plot.addPoints(x3, y3, Plot.LINE);
                window.drawPlot(plot);
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Ignoring points in a plot

Michael Schmid
Hi Mona,

if you plot a line where a point is NaN, it should break the line.
But I see, there is bug (caused by me); the line from the previous point
goes to the lower border of the image.

I'll send a mail to Wayne to fix it.

Here is a sample macro:

x = newArray( 1, 3, 4, 5, 6, 7, 8, 9, 11 );
y = newArray( 18, NaN, 3, 1, 7, 11, 11, 5, 2 );

Plot.create("Example Plot", "x", "y", x, y);

(For the macro, update ImageJ to the daily build; there is a problem with
NaN in macros in some recent ImageJ versions)

Michael
__________________________________________________________________

On Sat, November 7, 2015 05:21, mona_c wrote:
> Is it possible to ignore certain points when plotting a line plot? The
> following code is from plot example in Fiji. The bold line is changed,
> however it does not work i get: expected double[] y2 = { 18, Double.[], 3,
> 1, 7, 11, 11, 5, 2 };
> Changing it to Double.NaN also doesn't work correctly, since it goes to
> -inf.

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

Re: Ignoring points in a plot

Rasband, Wayne (NIH/NIMH) [E]
> On Nov 7, 2015, at 11:58 AM, Michael Schmid <[hidden email]> wrote:
>
> Hi Mona,
>
> if you plot a line where a point is NaN, it should break the line.
> But I see, there is bug (caused by me); the line from the previous point
> goes to the lower border of the image.
>
> I'll send a mail to Wayne to fix it.

Michael’s fix is in the latest ImageJ daily build (1.50e15).

> Here is a sample macro:
>
> x = newArray( 1, 3, 4, 5, 6, 7, 8, 9, 11 );
> y = newArray( 18, NaN, 3, 1, 7, 11, 11, 5, 2 );
>
> Plot.create("Example Plot", "x", "y", x, y);
>
> (For the macro, update ImageJ to the daily build; there is a problem with
> NaN in macros in some recent ImageJ versions)

The problem with NaNs was only with macro code used by the Process>Math>Macro command.

-wayne

> __________________________________________________________________
>
> On Sat, November 7, 2015 05:21, mona_c wrote:
>> Is it possible to ignore certain points when plotting a line plot? The
>> following code is from plot example in Fiji. The bold line is changed,
>> however it does not work i get: expected double[] y2 = { 18, Double.[], 3,
>> 1, 7, 11, 11, 5, 2 };
>> Changing it to Double.NaN also doesn't work correctly, since it goes to
>> -inf.
>
> --
> 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: Ignoring points in a plot

mona_c
Thank you. This solved the problem.