jzy3D从入门到弃坑_3使用jzy3D0.9画2D散点图--多条线条
Posted cloud-ken
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jzy3D从入门到弃坑_3使用jzy3D0.9画2D散点图--多条线条相关的知识,希望对你有一定的参考价值。
jzy3D从入门到弃坑_3
使用jzy3D0.9画2D散点图--多条线条
觉得有用的话,欢迎一起讨论相互学习~Follow Me
主要思路
- 将多个线条的二维数组读入Scatter对象
存入到同一个画布中
存入多个Scatter对象中
package momfo.metaheuristics.momfea;
import momfo.core.SolutionSet;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
import org.jzy3d.colors.Color;
import org.jzy3d.global.Settings;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.chart.Chart;
import java.awt.*;
public class PlotTwoD_alpha {
//如果要在一张图中添加多个点,我们采用首先取点,然后生成颜色的方式
public Scatter Setpoint(double[][] maxtrix, float[] rgb, float alpha, float width) {
Coord3d[] POINTS;
Color[] COLORS;
int size = maxtrix.length;//size
int numobj = maxtrix[0].length;//2
float x;
float y;
float z;
POINTS = new Coord3d[size];
COLORS = new Color[size];
for (int i = 0; i < size; i++) {
x = 0;
y = (float) maxtrix[i][0];
z = (float) maxtrix[i][1];
POINTS[i] = new Coord3d(x, y, z);
COLORS[i] = new Color(rgb[0], rgb[1], rgb[2], alpha);//表示RGB值和透明度
}
Scatter scatter = new Scatter(POINTS, COLORS, width);//width 表示线条宽度
return scatter;
}
}
在同一画布中将多个Scatter表示出来
package momfo.metaheuristics.momfea;
import java.awt.*;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.HashMap;
import momfo.core.*;
import momfo.util.comparators.LocationComparator;
import momfo.operators.crossover.CrossoverFactory;
import momfo.operators.mutation.MutationFactory;
import momfo.operators.selection.SelectionFactory;
import momfo.problems.benchmarks.*;
import momfo.qualityIndicator.QualityIndicator;
import momfo.util.JMException;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
import org.jzy3d.global.Settings;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class ReadPrintPF {
public static void main(String args[]) throws IOException, JMException, ClassNotFoundException {
ProblemSet problemSet; // The problem to solve
momfo.qualityIndicator.util.MetricsUtil utils_;
SolutionSet TruePFT1;
SolutionSet TruePFT2;
problemSet = CIHS.getProblem();
String pf1 = "PF/" + problemSet.get(0).getHType() + ".pf";
String pf2 = "PF/" + problemSet.get(1).getHType() + ".pf";
utils_ = new momfo.qualityIndicator.util.MetricsUtil();
// 返回的是一个solutionSet变量
//使用这种方式读取的SolutionSet没有决策变量
TruePFT1 = utils_.readNonDominatedSolutionSet(pf1);
TruePFT2 = utils_.readNonDominatedSolutionSet(pf2);
// TruePFT1.printObjectivesToFile("./src/main/java/momfo/metaheuristics/momfea/" + "CIHS" + "T1" + ".txt");
//并且可以发现目标函数值都是double类型的浮点数类型
// TruePFT1.printObjectives();
ReadPrintPFTools tools = new ReadPrintPFTools();
double[][] TruePFT1_Matrix = tools.writeObjectivesToMatrix(TruePFT1);
double[][] TruePFT2_Matrix = tools.writeObjectivesToMatrix(TruePFT2);
float[] rgb1 = {0, 0, 0};//黑色
float[] rgb2 = {(float) 0.5, (float) 0.5, (float) 0.5};//灰色
float alpha = (float) 0.5;
PlotTwoD_alpha pttwoD = new PlotTwoD_alpha();
Scatter scatter1 = pttwoD.Setpoint(TruePFT1_Matrix, rgb1, alpha, 5);
Scatter scatter2 = pttwoD.Setpoint(TruePFT2_Matrix, rgb2, alpha, 5);
Chart chart = new Chart(Quality.Advanced, "awt");
// add scatters
chart.getScene().add(scatter1);
chart.getScene().add(scatter2);
Settings.getInstance().setHardwareAccelerated(true);
//open chart
ChartLauncher.openChart(chart, new Rectangle(0, 0, 600, 600), "CIHS");
}
}
结果
以上是关于jzy3D从入门到弃坑_3使用jzy3D0.9画2D散点图--多条线条的主要内容,如果未能解决你的问题,请参考以下文章
将 jzy3d.canvas 转换为 awt.component