Plot without lines?

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

Plot without lines?

Gabriel Landini
Hi,

Does anybody have a suggestion about  how to produce a plot *without* the line
connecting the data points?

[...]
double[] a = Tools.getMinMax(datax);
double[] b = Tools.getMinMax(datay);

PlotWindow plot = new PlotWindow("Plot",set[0],set[1],datax,datay);
plot.setLimits(a[0],a[1],b[0],b[1]);
plot.draw();
[...]

I realise that after the plot window creation I can add points alone this way:
plot.addPoints(datax,datay,PlotWindow.CIRCLE);

but how do I create the plot window without the lines?
Many thanks

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Plot without lines?

Wayne Rasband
> Does anybody have a suggestion about  how to produce a plot
> *without* the line connecting the data points?
Here is an example macro that creates scatter plot:

     n = 5000;
     x = newArray(n);
     y = newArray(n);
     for (i=0; i<n; i++) {
         x[i] = i+n/3*(random()-0.5);
         y[i] = i+n/3*(random()-0.5);
     }
     Plot.create("Scatter Plot", "X", "Y");
     Plot.setLimits(0, n, 0, n);
     Plot.add("dots", x, y);

In a plugin it would look like this:

     int n = 5000;
     double[] x  = new double[n];
     double[] y  = new double[n];
     Random ran = new Random();
     for (int i=0; i<n; i++) {
         x[i] = i+n/3.0*(ran.nextDouble()-0.5);
         y[i] = i+n/3.0*(ran.nextDouble()-0.5);
     }
     Plot plot = new Plot("Scatter Plot", "X", "Y", new double[1],  
new double[1]);
     plot.setLimits(0, n, 0, n);
     plot.addPoints(x, y, Plot.DOT);
     plot.show();

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Plot without lines?

Gabriel Landini
Thanks Wayne & Joel.

On Saturday 17 December 2005 20:55, Rasband Wayne wrote:
>      Plot plot = new Plot("Scatter Plot", "X", "Y", new double[1],
> new double[1]);

The above works fine. There is a side effect: the "List" button in the plots  
window now shows "0 , 0.000" instead of the plot that I add next (but it
makes perfectly sense since one is passing an empty data set).

Perhaps it would be a bit more flexible for scatterplots if the plot, by
default, would output only symbols, and add an option to connect the points
if required.
I understand that this would require recode many other plotting areas of IJ
that are already working fine, so I am perfectly happy if stays as it is.

Cheers,

Gabriel