如何在图像上绘制散点图?
How to plot scatter plot on an image?
我正在尝试将 Matlab 中的 GUI 转换为 JavaFX 8 小程序。我想要一个散点图,其中图位于图像上,如下所示。
如上图所示,CIE 图与散点图结合在一起。我尝试使用堆栈窗格,但由于图像在其上方,因此图不可见。
编辑-
试图覆盖 layoutplotchildren():
class SuperScatterChart extends ScatterChart{
public SuperScatterChart(Axis arg0, Axis arg1) {
super(arg0, arg1 );
// TODO Auto-generated constructor stub
}
@Override
protected void layoutPlotChildren(){
ImageView iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true));
// How do I add iv1 to plot children?
super.layoutPlotChildren();
}
}
您将图像视图添加到具有
的绘图子项中
getPlotChildren().add(iv1);
您可能不需要在覆盖的 layoutPlotChildren()
方法中执行此操作:在构造函数中执行一次可能就足够了:
class SuperScatterChart extends ScatterChart<Number, Number>{
private final ImageView iv1 ;
public SuperScatterChart(NumberAxis xAxis, NumberAxis yAxis) {
super(xAxis, yAxis);
iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true));
getPlotChildren().add(iv1);
}
}
这会将图像放置在默认位置(我不认为绘图区域有任何默认布局,所以我认为它只会放置在左上角)。如需移动请加
@Override
protected void layoutPlotChildren() {
double x = ... ; // x coordinate of image in xAxis coordinates
double y = ... ; // y coordinate of image in yAxis coordinates
double layoutX = getXAxis().getDisplayPosition(x);
double layoutY = getYAxis().getDisplayPosition(y);
iv1.setLayoutX(layoutX);
iv1.setLayoutY(layoutY);
super.layoutPlotChildren();
}
请注意,这使您有机会使用 "plot coordinates" 轻松定位图像,即图表轴的坐标系,而不是基于像素的坐标系。
我正在尝试将 Matlab 中的 GUI 转换为 JavaFX 8 小程序。我想要一个散点图,其中图位于图像上,如下所示。
如上图所示,CIE 图与散点图结合在一起。我尝试使用堆栈窗格,但由于图像在其上方,因此图不可见。
编辑-
试图覆盖 layoutplotchildren():
class SuperScatterChart extends ScatterChart{
public SuperScatterChart(Axis arg0, Axis arg1) {
super(arg0, arg1 );
// TODO Auto-generated constructor stub
}
@Override
protected void layoutPlotChildren(){
ImageView iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true));
// How do I add iv1 to plot children?
super.layoutPlotChildren();
}
}
您将图像视图添加到具有
的绘图子项中getPlotChildren().add(iv1);
您可能不需要在覆盖的 layoutPlotChildren()
方法中执行此操作:在构造函数中执行一次可能就足够了:
class SuperScatterChart extends ScatterChart<Number, Number>{
private final ImageView iv1 ;
public SuperScatterChart(NumberAxis xAxis, NumberAxis yAxis) {
super(xAxis, yAxis);
iv1 = new ImageView(new Image("file:///C:/Desktop/cie.png",450,450,true,true));
getPlotChildren().add(iv1);
}
}
这会将图像放置在默认位置(我不认为绘图区域有任何默认布局,所以我认为它只会放置在左上角)。如需移动请加
@Override
protected void layoutPlotChildren() {
double x = ... ; // x coordinate of image in xAxis coordinates
double y = ... ; // y coordinate of image in yAxis coordinates
double layoutX = getXAxis().getDisplayPosition(x);
double layoutY = getYAxis().getDisplayPosition(y);
iv1.setLayoutX(layoutX);
iv1.setLayoutY(layoutY);
super.layoutPlotChildren();
}
请注意,这使您有机会使用 "plot coordinates" 轻松定位图像,即图表轴的坐标系,而不是基于像素的坐标系。