2009-12-06 61 views
6

我知道有很多比较Java绘图库的比较,但我没有找到我需要的东西。我只想要一个简单易用的工具包,它可以从一组坐标中创建散点图的图像。没有GUI,没有交互作用,没有花哨的显示,只有带点的基本XY坐标系统。Java:真正简单的散点图实用工具

使用能提供比我需要的更多功能的东西并不是世界末日,但我宁愿不要。你知道我想要的东西吗?

+0

您应该试试这个,它不是100%准确的,但应该完成这项工作[简单分散图](https://code.google.com/p/) simple-scatter-plot /) – user1406062 2012-09-26 21:25:28

回答

2

您的使用定制的JPanel绘制你的数据(未测试,但你的想法...)

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); 
(...) 
} 
2

我看了看周围的东西存在,并意识到jcckit在技术上是相当不错的,只是缺少一个简单的包装器,它可以很容易地使用。

所以我分叉它,并做了一个非常简单的包装。以下是如何使用:

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(); 

除了散点图,可以如果要使用“addPlot”和“阴谋”自由添加行同一轴线。

下面是代码:https://bitbucket.org/hughperkins/easyjcckit

+0

是否可以在不同的地块/套上设置不同的颜色? – 2014-12-30 14:22:02

1

你也可以检查Simple Java Plot。最小示例(无选项):

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");