jzy3d change color mapping

回眸只為那壹抹淺笑 提交于 2019-12-13 01:44:02

问题


I'm trying to create a surface chart using jzy3d package. Here's my code:

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

With the following code I set a default color mapping (blue for lower values, red for higher).

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

Is there any way to invert color mapping? I.e. red for lower values, blue/green for higher values.


回答1:


Solved by miself.

I used the method setDirection(false) on ColorMapRainbow:

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

The method inverts the default colors associated to each value, so that blue comes for higher values, and red for lowers.



来源:https://stackoverflow.com/questions/35793078/jzy3d-change-color-mapping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!