Scatter Plot will not change color

778 Views Asked by At

I'm trying to change the color of the points on my 3D Scatter Plot. The points change to black, not the color I want and the point on the key changes to the correct color. Does anyone know why this occurs?

import com.panayotis.gnuplot.JavaPlot;
import com.panayotis.gnuplot.plot.*;
import com.panayotis.gnuplot.style.NamedPlotColor;
import com.panayotis.gnuplot.style.PlotStyle;
import com.panayotis.gnuplot.style.Style;


public class ScatterPlot4D {

public static void main(String[] args) {

    int rows = 100;
    int D = 4;

    double [][] dataSet = new double [rows][D];
    for(int x = 0;x < rows; x++){
        for(int y = 0;y < D; y++){
            dataSet[x][y]=Math.random();
        }
    }

    JavaPlot p = new JavaPlot("C:\\Program Files\\gnuplot\\bin\\pgnuplot.exe");       
    p.newGraph3D();

    PlotStyle myStyle = new PlotStyle();
    myStyle.setStyle(Style.POINTS);
    myStyle.setLineType(NamedPlotColor.BLUE); 

    DataSetPlot myPlot = new DataSetPlot(dataSet);  
    myPlot.setPlotStyle(myStyle);

    p.addPlot(myPlot);

    p.splot();

}
}

What's weird is this works when graphing a function.

import com.panayotis.gnuplot.GNUPlot;
import com.panayotis.gnuplot.plot.*;
import com.panayotis.gnuplot.style.NamedPlotColor;
import com.panayotis.gnuplot.style.PlotStyle;
import com.panayotis.gnuplot.style.Style;

public class test3D {

public static void main(String[] args) {

    GNUPlot p = new GNUPlot("C:\\Program Files\\gnuplot\\bin\\pgnuplot.exe");

    p.newGraph3D();

    PlotStyle myStyle = new PlotStyle();
    myStyle.setStyle(Style.IMPULSES);
    myStyle.setLineType(NamedPlotColor.BLUE); 

    FunctionPlot myPlot = new FunctionPlot("tan(x)");
    myPlot.setTitle("3D Plot");
    myPlot.setPlotStyle(myStyle);

    p.addPlot(myPlot);

    p.splot();

}

}

gnuplot is being sent the commands:

gnuplot> set multiplot layout 1,2 rowsfirst downwards
multiplot> _gnuplot_error = 1
multiplot> splot '-' title 'Datafile 1' with points linetype rgb 'blue' ;_gnuplot_error = 0X
input data ('e' ends) > random data is here, not included for brevity
multiplot> if (_gnuplot_error == 1) print '_ERROR_'
 multiplot> unset multiplot
2

There are 2 best solutions below

0
On BEST ANSWER

As mgilson said in the comments:

 use myStyle.setLineType(3);

(@mgilson, if you want credit for the answer, just write it yourself, message me and I'll accept it instead_

1
On

well, I think that what you need is to use setPointType instead of setLineType in the scatter graph, as is has no Lines. it has only Points.