I'm using org.jzy3d
package (v 0.9) to create Surface plots
.
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;
}
};
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);
org.jzy3d.chart.Chart chart = new org.jzy3d.chart.Chart(Quality.Advanced,"swing");
chart.getScene().getGraph().add(surface);
IAxeLayout l = chart.getAxeLayout();
l.setXAxeLabel("Observation");
l.setYAxeLabel("Week");
l.setZAxeLabel("Rate");
l.setMainColor(org.jzy3d.colors.Color.GRAY);
JPanel p = new JPanel(new BorderLayout()); //another panel will be added to this panel and aligned left (BorderLayout.WEST)
p.add((JPanel)chart.getCanvas(),BorderLayout.CENTER);
... and this is what I get:
I'd like to customize this chart further, but I really cannot figure out how.
In particular I'd like to:
Zoom out the chart to fit my panel (in the attached picture you can see that the bottom of the chart is not visible);
Format axis labels (e.g. 0.6 displayed instead of 0.600000 for z axis, 2 displayed instead of 2.000 for x axis and so on...);
Invert color mapping (e.g. red when z value is lower, blue/green when z value is higher).
I solved by myself 2 of the 3 above mentioned points. Here are the solution just in case someone is interested:
Format Axis Labels: I createad a custom ITickRenderer
which formats the axis labels basing on a DecimalFormat
I have previously defined.
ITickRenderer r = new ITickRenderer(){
@Override
public String format(float arg0) {
return m.df.format(arg0);
}
};
Invert color mapping: I posted the solution here.