2016-03-04 108 views
1

我試圖使用jzy3d包創建曲面圖。這裏是我的代碼:jzy3d更改顏色映射

int stepsX = 6; 
Range rX = new Range(1,6); 
int stepsY = 7; 
Range rY = new Range(0,6); 

Mapper mapper = new Mapper(){ 
    @Override 
    public double f(double x, double y) { 
     return //My function to get Z value; 
    } 
}; 

// Create a surface drawing that function 
org.jzy3d.plot3d.primitives.Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(rX, stepsX, rY, stepsY), mapper); 
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new org.jzy3d.colors.Color(1, 1, 1, .5f))); 
surface.setFaceDisplayed(true); 
surface.setWireframeDisplayed(false); 
//surface.setWireframeColor(org.jzy3d.colors.Color.GRAY); 

// Create a chart and add the surface 
org.jzy3d.chart.Chart chart = new org.jzy3d.chart.Chart(Quality.Advanced,"swing"); 
chart.getScene().getGraph().add(surface); 

JPanel p = new JPanel(new BorderLayout()); 
p.add((JPanel)chart.getCanvas(),BorderLayout.CENTER); 

用下面的代碼我設置默認顏色映射(藍色較低值,紅色爲更高)。

surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new org.jzy3d.colors.Color(1, 1, 1, .5f))); 

有什麼方法可以顛倒顏色映射嗎?即紅色表示較低值,藍色/綠色表示較高值。

回答

1

解決不當。

我所使用的方法setDirection(false)ColorMapRainbow

ColorMapRainbow colorScale = new ColorMapRainbow(); 
colorScale.setDirection(false); 
surface.setColorMapper(new ColorMapper(colorScale, surface.getBounds().getZmin(), surface.getBounds().getZmax())); 

的方法反轉關聯到每個值的默認顏色,使得藍色來爲更高的值,以及對於紅色降低。