Scatter Plot will not change color

丶灬走出姿态 提交于 2019-12-24 09:58:40

问题


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

回答1:


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.




回答2:


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_



来源:https://stackoverflow.com/questions/11396616/scatter-plot-will-not-change-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!