Login  Register

Re: ij.gui.Plot enhancement request...

Posted by jmutterer on Nov 13, 2008; 1:44pm
URL: http://imagej.273.s1.nabble.com/ij-gui-Plot-enhancement-request-tp3694518p3694521.html

The trick is to call the contructor with two null double arrays. The
following plugin allows listing of the data points.

public class plot_test implements PlugIn {

    public void run(String arg) {
        if (IJ.versionLessThan("1.30c"))
            return;

        float[] x = {0.1f, 0.25f, 0.35f, 0.5f,
0.61f,0.7f,0.85f,0.89f,0.95f}; // x-coordinates
        float[] y = {2f,5.6f,7.4f,9f,9.4f,8.7f,6.3f,4.5f,1f}; //
x-coordinates

        float[] x2 = {0f,1f};
        float[] y2 = {0f,1f};

        double[] a = null;
        double [] b =null;

        Plot plot = new Plot("Example Plot","X Axis","Y Axis",a,b);
        plot.setLimits(0, 1, 0, 10);
        plot.setLineWidth(2);
        plot.addPoints(x,y,PlotWindow.X);
        plot.addPoints(x2,y2,PlotWindow.LINE);
        plot.show();
    }
}


Jerome


On Thu, Nov 13, 2008 at 11:41 AM, Michael Schmid <[hidden email]>wrote:

> Hi Woody,
>
> yes, I agree, the Plot class stores only one set of data, it is the data
> that you submit with the constructor. Everything that you add later is
> plotted (in the sequence that you add it) but not stored as data. Finally,
> with Plot.show() [or in a java program, plot.show()] the data submitted with
> the constructor are plotted with the current color and line type settings,
> but always as a line.
> Plot.draw calls drawPolyline, not addPoints, so there is no way out with
> the current version of ImageJ (sorry, Jerome, your version won't let you
> list the data)
>
> It is not so clear what could be a good solution.
>
> - Storing all data and listing them in separate columns?
> This has the disadvantage that auxiliary lines such as your diagonal or a
> horizontal line plotted to show the x axis (at y=0 for plots with positive
> and negative values) would generate extra data in the list.
> Also, it might break existing macros or procedures relying on getting only
> one y column of data.
>
> - Adding a Plot.setShape(shape) method and calling addPoints instead of
> drawPolyline in Plot.draw?
> This would perpetuate the counterintuitive problem that you have to set the
> shape, line width and color for the data passed in the constructor after all
> the other addPoints methods.
>
> - Passing shape, size/lineWidth and color of the initial data with the
> constructor?
> This would add at least two very long constructors (for float and double
> arrays).
>
>   public Plot(String title, String xLabel, String yLabel, double[] xValues,
> double[] yValues, int flags, int shape, int lineWidth, Color color)
>
> Also not extremely elegant...
>
> Any better idea?
>
> Michael
> ________________________________________________________________
>
>
> On 13 Nov 2008, at 08:14, Jerome Mutterer wrote:
>
>  Unintuitively, the last serie added to a plot is drawn first. Add the line
>> reference after your data points, and the list button will list your
>> points.
>>
>> Jerome.
>>
>> Plot.add("dots", x, y);
>> Plot.add("line", newArray(0,x.length),newArray(0,y.length));
>>
>> On Thu, Nov 13, 2008 at 7:32 AM, Jeffrey B. Woodward <
>> [hidden email]> wrote:
>>
>>  ImageJ'ers/Wayne,
>>>
>>> I am trying to use the ij.gui.Plot class to create a scatter plot.
>>> Actually, the Plot contains both a scatter plot and a simple curve
>>> (diagonal
>>> line with points at [0,0] and [max,max]). The diagonal line is just for a
>>> visual reference; the real data points are what make up the scatter plot.
>>> The issue is that in doing this, I can't find a way for the user to use
>>> the
>>> List button (or the Save button) to get a listing of the data points.
>>> This
>>> is because the List/Save buttons seem only appear to operate on the
>>> points
>>> used in the constructor (in my case the endpoints of the reference
>>> diagonal), but my data points for the scatter plot are added after
>>> construction using the addPoints() method.
>>>
>>> My first thought was to supply my scatter plot points in the constructor
>>> and add the reference line with the addPoints() method; however, I don't
>>> see
>>> any way to avoid drawing them as a polyline doing it this way -- I want a
>>> scatter plot of those points, not a polyline!
>>>
>>> Hopefully I am missing something obvious in the API/source code, but in
>>> case if I am not, is this an enhancement that the ImageJ community is
>>> interested in? Should I take a crack at this myself, or is somebody else
>>> interested enough to do it?
>>>
>>> BTW: I suppose that there may be a hack/workaround for my specific
>>> case...perhaps I could supply my points in the constructor drawn with a
>>> fully transparent color/invisible-ink, then add the points for my
>>> reference
>>> diagonal using the addPoints() method with a LINE shape and appropriate
>>> color, and lastly, add the scatter plot points [again] with the
>>> addPoints()
>>> method with a DOT shape and appropriate color. Seems ugly -- probably
>>> doomed
>>> to failure -- other suggestions/hacks/workarounds/free-therapy-sessions
>>> are
>>> welcome.
>>>
>>> Many thanks,
>>>
>>> -Woody
>>>
>>>