annotate yetilab/plot/plot.yeti @ 149:145431ff5ee3

Use times as well as values
author Chris Cannam
date Sun, 28 Apr 2013 10:42:45 +0100
parents b973e8a31bd6
children e65bdec6470e
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@149 55 plotCurve curve =
Chris@148 56 (chart = new Chart(Quality#Nicest);
Chris@148 57 scene = chart#getScene();
Chris@149 58 xx = map (.time) curve;
Chris@149 59 yy = map (.value) curve;
Chris@149 60 line = new FlatLine2d(xx as ~float[], yy as ~float[], 0);
Chris@148 61 line#setWireframeDisplayed(true);
Chris@148 62 line#setWireframeColor(Color#BLACK);
Chris@148 63 line#setWireframeWidth(2);
Chris@148 64 line#setFaceDisplayed(false);
Chris@148 65 scene#add(line);
Chris@148 66 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
Chris@149 67 /*
Chris@148 68 axes = chart#getAxeLayout();
Chris@148 69 axes#setXAxeLabelDisplayed(false);
Chris@148 70 axes#setYAxeLabelDisplayed(false);
Chris@148 71 axes#setZAxeLabelDisplayed(true);
Chris@148 72 axes#setZAxeLabel("unit goes here"); //!!!
Chris@148 73 axes#setYTickLabelDisplayed(false);
Chris@149 74 */
Chris@148 75 ChartLauncher#openChart(chart);
Chris@148 76 ());
Chris@148 77
Chris@110 78 plotStructure structure =
Chris@110 79 case structure of
Chris@110 80 Grid matrix:
Chris@115 81 plotMatrix matrix;
Chris@148 82 Curve curve:
Chris@149 83 plotCurve curve;
Chris@110 84 _: failWith "Cannot plot this structure (only grids implemented so far)";
Chris@110 85 esac;
Chris@108 86
Chris@115 87 {
Chris@119 88 newMatrixMapper,
Chris@119 89 newMatrixLogMapper,
Chris@119 90 newMapper,
Chris@115 91 plotMatrix,
Chris@119 92 plotStructure,
Chris@115 93 }
Chris@110 94