JFreeChart使用colourmaps在2D图形中表示3D数据

时间:2011-12-09 04:58:32

标签: java graph dataset jfreechart renderer

我目前正在尝试使用JFreeChart在2D图表中表示3D数据。

基本上,我有一个名为data[i][j]的二维数组。 ij代表我想要绘制的yx坐标。 data[i][j]的值表示频率值,我想在图表中将其表示为颜色。

我不完全确定这样的东西会被调用,但它看起来像这样:

enter image description here

现在我一直在尝试使用XYBlockRenderer执行此操作,但是我遇到了定义数据集的问题。我正在尝试使用DefaultXYZDataset,但我真的很困惑如何在这里定义数据。

有人可以解释如何使用DefaultXYZDataset来完成这项任务吗?

DefaultXYZDataset dataset = new DefaultXYZDataset();

Concentration.dataoutHeight = Concentration.dataout[0].length;

System.out.println(Concentration.dataoutHeight);
System.out.println(ImageProcessor.MAXCBVINT);
double[][] data = new double[3][ImageProcessor.MAXCBVINT];


for (int i = 0; i < Concentration.dataoutHeight; i++) {
    for (int j = 0; j < ImageProcessor.MAXCBVINT; j++) {
        data[0][j] = j;//x value
        data[1][j] = i;//y value
        data[2][j] = Concentration.dataout[j][i][0];//Colour
    }
    dataset.addSeries(i, data);

}
NumberAxis xAxis = new NumberAxis("Intensity");
xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
xAxis.setLowerMargin(0.0);
xAxis.setUpperMargin(0.0);
NumberAxis yAxis = new NumberAxis("Distance to Closest Blood Vessel (um)");
yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
yAxis.setLowerMargin(0.0);
yAxis.setUpperMargin(0.0);
XYBlockRenderer renderer = new XYBlockRenderer();
PaintScale scale = new GrayPaintScale(0, 10000.0);
renderer.setPaintScale(scale);
renderer.setBlockHeight(1);
renderer.setBlockWidth(1);
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinePaint(Color.white);
JFreeChart chart = new JFreeChart("Surface Plot", plot);
chart.removeLegend();
chart.setBackgroundPaint(Color.white);

ChartFrame frame = new ChartFrame("Surface Map - "
    + (Concentration.testing ? "TESTING using "
    + Concentration.testfile : currentFile.getName()), chart);
frame.pack();
frame.setVisible(true);

1 个答案:

答案 0 :(得分:1)

您有两种选择:

  1. 将它们表示为3d 3D Lib for JFreeChart

  2. 您需要使用类XYBlockRenderer,这正是您所要求的。您可以下载JFreeChart演示集合,其中包含此代码。 (类here的源代码) 还有this完整代码示例与4D非常相似。