annotate yetilab/plot/plot.yeti @ 148:b973e8a31bd6

Basic curve plot
author Chris Cannam
date Sun, 28 Apr 2013 10:35:29 +0100
parents 4065178f776b
children 145431ff5ee3
rev   line source
Chris@108 1 module yetilab.plot.plot;
Chris@108 2
Chris@108 3 import org.jzy3d.plot3d.builder: Mapper;
Chris@119 4 import org.jzy3d.maths: Range, Coord3d;
Chris@108 5 import org.jzy3d.chart: Chart, ChartLauncher;
Chris@108 6 import org.jzy3d.plot3d.builder: Builder;
Chris@108 7 import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid;
Chris@108 8 import org.jzy3d.colors.colormaps: ColorMapRainbow;
Chris@119 9 import org.jzy3d.colors: ColorMapper, Color;
Chris@108 10 import org.jzy3d.plot3d.rendering.canvas: Quality;
Chris@119 11 import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode;
Chris@148 12 import org.jzy3d.plot3d.primitives: FlatLine2d, Point;
Chris@108 13
Chris@108 14 newMatrixMapper matrix =
Chris@108 15 (class MMapper extends Mapper
Chris@108 16 double f(double x, double y)
Chris@117 17 result = matrix.getAt y x;
Chris@117 18 println "f(\(x),\(y)) -> \(result)";
Chris@117 19 result
Chris@108 20 end;
Chris@108 21 new MMapper());
Chris@108 22
Chris@108 23 newMatrixLogMapper matrix =
Chris@108 24 (class MMapper extends Mapper
Chris@108 25 double f(double x, double y)
Chris@108 26 ln (matrix.getAt y x)
Chris@108 27 end;
Chris@108 28 new MMapper());
Chris@108 29
Chris@108 30 newMapper mapFunction =
Chris@108 31 (class FMapper extends Mapper
Chris@108 32 double f(double x, double y)
Chris@108 33 mapFunction x y
Chris@108 34 end;
Chris@108 35 new FMapper());
Chris@108 36
Chris@115 37 plotMatrix matrix =
Chris@117 38 (mapper = newMatrixMapper matrix;
Chris@108 39 size = matrix.size;
Chris@119 40 xrange = new Range(0, size.columns - 1);
Chris@119 41 yrange = new Range(0, size.rows - 1);
Chris@108 42 grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows);
Chris@112 43 println "Matrix size: \(size)";
Chris@117 44 surface = Builder#buildOrthonormal(grid, mapper); //??? big?
Chris@117 45 println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())";
Chris@121 46 surface#setFaceDisplayed(true);
Chris@108 47 surface#setWireframeDisplayed(true);
Chris@108 48 surface#setWireframeColor(Color#BLACK);
Chris@112 49 // chart = new Chart(Quality#Fastest, "swing");
Chris@112 50 chart = new Chart(Quality#Nicest);
Chris@108 51 chart#getScene()#getGraph()#add(surface);
Chris@115 52 ChartLauncher#openChart(chart);
Chris@115 53 ());
Chris@108 54
Chris@148 55 plotCurve values is list?<number> -> () =
Chris@148 56 (chart = new Chart(Quality#Nicest);
Chris@148 57 scene = chart#getScene();
Chris@148 58 n = length values;
Chris@148 59 line = new FlatLine2d([0..n-1] as ~float[], values as ~float[], 0);
Chris@148 60 line#setWireframeDisplayed(true);
Chris@148 61 line#setWireframeColor(Color#BLACK);
Chris@148 62 line#setWireframeWidth(2);
Chris@148 63 line#setFaceDisplayed(false);
Chris@148 64 scene#add(line);
Chris@148 65 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
Chris@148 66 axes = chart#getAxeLayout();
Chris@148 67 axes#setXAxeLabelDisplayed(false);
Chris@148 68 axes#setYAxeLabelDisplayed(false);
Chris@148 69 axes#setZAxeLabelDisplayed(true);
Chris@148 70 axes#setZAxeLabel("unit goes here"); //!!!
Chris@148 71 axes#setYTickLabelDisplayed(false);
Chris@148 72 ChartLauncher#openChart(chart);
Chris@148 73 ());
Chris@148 74
Chris@110 75 plotStructure structure =
Chris@110 76 case structure of
Chris@110 77 Grid matrix:
Chris@115 78 plotMatrix matrix;
Chris@148 79 Curve curve:
Chris@148 80 plotCurve (map (.value) curve); //!!! this is wrong, but just to see
Chris@110 81 _: failWith "Cannot plot this structure (only grids implemented so far)";
Chris@110 82 esac;
Chris@108 83
Chris@115 84 {
Chris@119 85 newMatrixMapper,
Chris@119 86 newMatrixLogMapper,
Chris@119 87 newMapper,
Chris@115 88 plotMatrix,
Chris@119 89 plotStructure,
Chris@115 90 }
Chris@110 91