我如何创建一个JFreeChart散点图最佳拟合线 [英] How would I create a JFreeChart scatterplot best fit line

查看:369
本文介绍了我如何创建一个JFreeChart散点图最佳拟合线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要包含在JFreeChart散点图中的分数列表。这很好,但我现在想要一个最合适的线。经过一些搜索,JFreeChart不直接支持这样的计算,所以我想做的就是自己计算,然后手动在图表中加一条线。如何在散点图中获得一行?

I have an arraylist of points I want to include in a JFreeChart scatterplot. That works fine, but I now want a best fit line on it. After some searching, JFreeChart doesn't support such calculations directly, so what I want to do is calculate it myself and then stick a line into the chart manually. How do I get a line in a scatterplot?

        XYSeries series = new XYSeries("Data");
        for (Point p : points) {
           series.add(p.getX(), p.getY());
        }
        XYSeriesCollection dataset = new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createScatterPlot(chartName, "Mass", parameter, dataset, PlotOrientation.VERTICAL, false, true, true);
        return chart;


推荐答案

使用内置的 回归 方法 getOLSRegression() 或统计库,例如 Apache Commons Math 使用简单回归确定这样一条线的斜率和截距。将原始数据添加到散点图中,如图所示这里。添加 XYLineAnnotation 表示您的行的端点,如图所示这里

Use the built-in Regression method getOLSRegression() or a statistical library such as Apache Commons Math to determine the slope and intercept of such a line using simple regression. Add your original data to a scatter plot, as shown here. Add an XYLineAnnotation representing the endpoints of your line, as shown here.

这篇关于我如何创建一个JFreeChart散点图最佳拟合线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆