jzy3d change color mapping

2019-08-14 04:10发布

问题:

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.



标签: java swing jzy3d