/// <summary> /// Draws NPlot.ImagePlot. /// Does Clear(), axis are hidden. /// Can be used for icons as well. /// </summary> /// <param name="plotSurface2D"> /// A <see cref="IPlotSurface2D"/> /// </param> /// <param name="table"> /// A <see cref="Table3D"/> /// </param> public static void Draw(IPlotSurface2D plotSurface2D, Table3D table) { float[] valuesZ = table.GetValuesZasFloats (); // NPlot ImagePlot, needs 2D-array of type double int cyi = table.CountY - 1; int cx = table.CountX; double[,] data = new double[table.CountY, cx]; for (int i = 0; i < valuesZ.Length; i++) { // [row, col], include y-reordering, same effect as plotSurface.YAxis1.Reversed // not using using YAxis1.Reversed seems to avoid a display bug (white row sometimes included) data[cyi - i / cx, i % cx] = valuesZ[i]; } var ip = new ImagePlot (data); ip.Gradient = gradient; plotSurface2D.Clear (); plotSurface2D.Add (ip); plotSurface2D.XAxis1.Hidden = true; plotSurface2D.YAxis1.Hidden = true; }
// static string AnnotationStr (Table2D table2D) // { // return string.Format ("Min: {0} Max: {1} Avg: {2}", table2D.Ymin.ToString (), table2D.Ymax.ToString (), table2D.Yavg.ToString ()); // } // TODO investigate piping binary data via standard input, avoiding temp file // However temp file might be useful for manual gnuplot experiments. static void WriteGnuPlotBinary(BinaryWriter bw, Table3D table3D) { /* from gnuplot help PDF page 157, "matrix binary": Single precision floats are stored in a binary file as follows: <N+1> <y0> <y1> <y2> ... <yN> <x0> <z0,0> <z0,1> <z0,2> ... <z0,N> <x1> <z1,0> <z1,1> <z1,2> ... <z1,N> */ // x <-> y designation from above (manual) seems wrong as xlabel etc. matches code below! float[] valuesX = table3D.ValuesX; // write first float: <N+1> bw.Write ((float)(valuesX.Length)); // x axis foreach (var x in valuesX) { bw.Write (x); } float[] valuesY = table3D.ValuesY; float[] valuesZ = table3D.GetValuesZasFloats (); for (int iy = 0; iy < valuesY.Length; iy++) { bw.Write (valuesY[iy]); for (int ix = 0; ix < valuesX.Length; ix++) { bw.Write (valuesZ[ix + iy * valuesX.Length]); } } }
void Show3D(Table3D table) { if (table == null) return; var valuesZ = table.GetValuesZasFloats (); var tableUI = new GtkWidgets.TableWidget (coloring, table.ValuesX, table.ValuesY, valuesZ, table.Zmin, table.Zmax); tableUI.TitleMarkup = GtkWidgets.TableWidget.MakeTitleMarkup (table.Title, table.UnitZ); tableUI.AxisMarkupX = GtkWidgets.TableWidget.MakeMarkup (table.NameX, table.UnitX); tableUI.AxisMarkupY = GtkWidgets.TableWidget.MakeMarkup (table.NameY, table.UnitY); // HACK FormatValues, no good digits algorithm yet int digits = ScoobyRom.Data.AutomaticMinDigits(valuesZ); if (digits <= 3) { tableUI.FormatValues = ScoobyRom.Data.ValueFormat(digits); } else{ tableUI.FormatValues = table.Zmax < 30 ? "0.00" : "0.0"; if (table.Zmax < 10) tableUI.FormatValues = "0.000"; } // Viewport needed for ScrolledWindow to work as generated table widget has no scroll support var viewPort = new Gtk.Viewport (); viewPort.Add (tableUI.Create ()); Gtk.Widget previous = this.scrolledwindowTable3D.Child; if (previous != null) this.scrolledwindowTable3D.Remove (previous); // previous.Dispose () or previous.Destroy () cause NullReferenceException! this.scrolledwindowTable3D.Add (viewPort); this.scrolledwindowTable3D.ShowAll (); }