我正在使用org.jzy3d
包(v 0.9)来创建曲面图
。
这是我的代码:
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);
...这就是我得到的:
我想进一步定制这个图表,但我真的不知道如何做。
我特别想:
缩小图表以适合我的面板(在附图中您可以看到图表底部不可见);
设置轴标签格式(例如,z 轴显示 0.6,而不是 0.600000,x 轴显示 2,而不是 2.000,等等...);
反转颜色映射(例如,z 值较低时为红色,z 值较高时为蓝色/绿色)。
最佳答案
我自己解决了上述 3 点中的 2 点。以下是解决方案,以防万一有人感兴趣:
设置轴标签格式:我创建了一个自定义
ITickRenderer
,它根据我之前定义的DecimalFormat
来格式化轴标签。ITickRenderer r = new ITickRenderer(){ @Override public String format(float arg0) { return m.df.format(arg0); } };
反转颜色映射:我发布了解决方案 here .
关于java - 如何自定义 jzy3d 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35743327/