散点图不会改变颜色
问题描述:
我试图改变3D散点图上点的颜色。点变为黑色,而不是我想要的颜色,并且键上的点变为正确的颜色。有谁知道为什么发生这种情况?散点图不会改变颜色
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();
}
}
有什么奇怪的是,这是图形函数时的作品。
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正在发送的命令:
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
答
由于mgilson在评论中说:
use myStyle.setLineType(3);
(@mgilson,如果你想要信用为答案,就自己写了,给我发短信,我会接受它instead_
答
很好,我认为你需要的是使用setPointType代替setLineType在散点图,因为是没有行。它只有点。
+0
setPointType将int作为参数。尝试各种选项,我只能改变点的形状,而不是颜色。 http://sparky.rice.edu/gnuplot.html让我觉得我可以用int来改变颜色,但我似乎无法让它工作。 – Daniel 2012-07-10 13:48:41
有什么如何将GNUPlot内容转储到文件中,以便我们可以看到gnuplot正在处理什么? – mgilson 2012-07-10 02:39:30
@mgilson,yup我将它包含在编辑中 – Daniel 2012-07-10 13:23:25
PlotStyle类是否提供了“setLineColor”方法?本质上,问题在于您的生成'...用点线型rgb'blue''而不用'...用点linecolor rgb'blue'' – mgilson 2012-07-10 14:04:58