【问题标题】:JFreeChart to represent 3D data in a 2D graph using colourmapsJFreeChart 使用颜色图在 2D 图中表示 3D 数据
【发布时间】:2011-12-09 04:58:32
【问题描述】:

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

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

我不完全确定这样的东西叫什么,但它看起来像这样:

现在我一直在尝试使用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);

【问题讨论】:

标签: java graph dataset jfreechart renderer


【解决方案1】:

你有两个选择:

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

  2. 您需要使用类:XYBlockRenderer,它完全符合您的要求。您可以下载 JFreeChart 演示集合,其中给出了代码。 (here类的源代码) 还有this与4D非常相似的完整代码示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 2015-01-13
    • 2017-12-24
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    相关资源
    最近更新 更多