简体   繁体   中英

How to Customize jzy3d Chart

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 (eg 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 (eg 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM