Java:非常簡單的散點圖實用程序 (Java: Really simple scatter plot utility)


問題描述

Java:非常簡單的散點圖實用程序 (Java: Really simple scatter plot utility)

I know there are many comparisons of java plotting libraries out there, but I'm not finding what I need. I just want a mind‑numbingly simple toolkit that creates images of scatterplots from a set of coordinates. No GUI, no interaction, no fancy display, just a basic XY coordinate system with points.

It wouldn't be the end of the world to use something that offers a lot more functionality than I need, but I'd rather not. Do you know of anything like what I'm looking for?

‑‑‑‑‑

參考解法

方法 1:

Have you looked at JFreeChart?  While it can do some very advanced things, it also does the simple as well.  Shown below is a screenshot of its scatter plot capability.

(source: jfree.org)  

方法 2:

I looked around at what existed, and realized that jcckit is technically pretty good, but just lacks a simple wrapper around it to make it easy to use.

So I forked it and made a really simple wrapper.  Here's how to use:

import static easyjcckit.QuickPlot.*;

double[] xaxis = new double[]{0,1,2,3,4,5};
double[] yvalues = new double[]{0,1,4,9,16,25};
scatter( xaxis, yvalues ); // create a plot using xaxis and yvalues
double[] yvalues2 = new double[]{0,1,2,3,4,5};
addScatter( xaxis, yvalues2 ); // create a second plot on top of first

System.out.println("Press enter to exit");
System.in.read();

As well as scatter plots, you can freely add lines to the same axes if you wish using 'addPlot' and 'plot'.

Here is the code: https://bitbucket.org/hughperkins/easyjcckit

方法 3:

You an use a custom JPanel to draw your data(not tested, but you get the idea...)

private List<Point2D> data=(...);

JPanel pane=new JPanel()
{
protected paintComponent(Graphics2D g)
{
super.paintComponent(g);
int minx=(...),miny=(...),maxx=(...),maxy=(...);
for(Point2D p: data)
 {
 int x=((p.getX()‑minx)/(maxx‑minx))*this.getWidth();
 int y=((p.getY()‑miny)/(maxy‑miny))*this.getHeight();
 g.drawLine(x‑5,y,x+5,y);
 g.drawLine(x,y‑5,x,y+5);
 }
}
pane.setOpaque(true);
(...)
anotherComponent.add(pane);
(...)
}

方法 4:

Also you could check Simple Java Plot. Minimal example (no options):

Plot plot = Plot.plot(null).
    // setting data
    series(null, Plot.data().
        xy(1, 2).
        xy(3, 4), null);
// saving sample_minimal.png
plot.save("sample_minimal", "png");

(by Nick HeinerJasCavHugh PerkinsPierreyuriy‑g)

參考文件

  1. Java: Really simple scatter plot utility (CC BY‑SA 3.0/4.0)

#scatter-plot #java #charts






相關問題

matplotlib:重繪前清除散點數據 (matplotlib: clearing the scatter data before redrawing)

使用 matplotlib 保存散點圖動畫 (Saving scatterplot animations with matplotlib)

在 matplotlib 中圍繞散點圖中的數據點繪製平滑多邊形 (draw a smooth polygon around data points in a scatter plot, in matplotlib)

Java:非常簡單的散點圖實用程序 (Java: Really simple scatter plot utility)

如何在多個圖中選擇一個要編輯的圖? (How to select one plot to be edit in multiple plots?)

d3js散點圖自動更新不起作用 (d3js scatter plot auto update doesnt work)

散點圖中的重疊趨勢線,R (Overlapping Trend Lines in scatterplots, R)

DC.JS 散點圖選擇 (DC.JS scatterplot chart selection)

固定散景散點圖中的軸間距(刻度) (Fixing axis spacing (ticks) in Bokeh scatter plots)

如何在顏色條上繪製散點圖? (How to plot scatter plot points on a colorbar?)

如何在散點圖中以均勻間隔更改 x 軸值? (How to change x axis value with even interval in scatter plot?)

如何在散點圖(地理地圖)上標註數據? (How to annotate data on the scatter plot (geo map)?)







留言討論