简体   繁体   English

带有在另一个类中计算的 xy 数据的简单 Java Plot

[英]Simple Java Plot with x-y data calculated in another class

I'm looking at using http://yuriy-g.github.io/simple-java-plot/ for simple xy scatter plots.我正在考虑使用http://yuriy-g.github.io/simple-java-plot/来绘制简单的 xy 散点图。 How can I get the code below:我怎样才能得到下面的代码:

public static void main(String[] args) throws IOException {
    // configuring plot options
    Plot plot = Plot.plot(Plot.plotOpts().
            title("Intensity vs. Distance").
            legend(Plot.LegendFormat.BOTTOM)).
        xAxis("mm", Plot.axisOpts().
            range(0, 10)).
        yAxis("I", Plot.axisOpts().
            range(0, 1000)).
        series("Data", Plot.data().
            xy(0, 1000).
            xy(1, 50).
            xy(2, 25),
            Plot.seriesOpts().
                marker(Plot.Marker.DIAMOND).
                markerColor(Color.GREEN).
                color(Color.BLACK));
    plot.save("sample_data", "png");
}

to programmatically read in multiple xy points (ie xy(X1, Y2). xy(X2, Y2). ...) from elsewhere.从其他地方以编程方式读取多个 xy 点(即 xy(X1, Y2). xy(X2, Y2). ...)。 ie I have another class that calculates these xy points and want to pass these to plot them or alternatively call plotting.即我有另一个类计算这些 xy 点并希望通过这些来绘制它们或调用绘图。

From the Data class in Plot.java it seems to be possible.Plot.java 中Data来看,这似乎是可能的。

PS I'm new to Java. PS我是Java新手。

Worked out it can be done like this:算出来可以这样做:

private static final double[] xvals = new double[4];
private static final double[] yvals = new double[4];

static {
    xvals[0] = 1;
    xvals[1] = 2;
    xvals[2] = 3;
    xvals[3] = 4;
}

static {
    yvals[0] = 1000;
    yvals[1] = 500;
    yvals[2] = 250;
    yvals[3] = 125;
}

public static void main(String[] args) throws IOException {
    // configuring plot options
    Plot plot = Plot.plot(Plot.plotOpts().
            title("Intensity vs. Distance").
            legend(Plot.LegendFormat.BOTTOM)).
        xAxis("mm", Plot.axisOpts().
            range(0, 10)).
        yAxis("I", Plot.axisOpts().
            range(0, 1000)).
        series("Data", Plot.data().
            xy(xvals, yvals),
            Plot.seriesOpts().
                marker(Plot.Marker.DIAMOND).
                markerColor(Color.GREEN).
                color(Color.BLACK));
    plot.save("sample_data", "png");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM