To run the following examples, please run the LabTalk script below first to prepare a new workbook with the "Group.DAT" data. Make sure that the new created workbook should be active before running each example.
newbook; // create a new workbook fname$ = system.path.program$ + "Samples\Graphing\Group.DAT"; // file path impasc; // import the file to the new workbook
Minimum Origin Version Required: Origin 8 SR2
This example is used to create a simple scatter plot with some changes on the symbol type, size, color, etc..
void simple_scatter_plot() { Worksheet wks = Project.ActiveLayer(); // get worksheet with group.dat data if( !wks ) { out_str("Please activate worksheet with group.dat data!"); return; } // plot simple scatter plot DataRange dr; dr.Add(wks, 0, "X"); dr.Add(wks, 1, "Y"); GraphPage gp; gp.Create("scatter"); // create scatter graph if( !gp ) { out_str("Failed to create scatter plot!"); return; } GraphLayer gl = gp.Layers(0); int nPlot = gl.AddPlot(dr, IDM_PLOT_SCATTER); // add plot to layer if( nPlot >= 0 ) // if add plot successfully { DataPlot dp = gl.DataPlots(0); dp.SetSymbol(12); // set symbol shape: empty circle dp.SetColor(SYSCOLOR_BLUE); // set color: blue Tree trFormat; trFormat.Root.Symbol.Size.nVal = 12; // set size: 12 trFormat.Root.DropLines.Vertical.nVal = true; // add vertical droplines if( 0 == dp.UpdateThemeIDs(trFormat.Root) ) { dp.ApplyFormat(trFormat, true, true); } gl.Rescale(); } }
Minimum Origin Version Required: Origin 8 SR5
This example is used to create a scatter central plot with some changes on the symbol color and shape.
void scatter_central_plot() { Worksheet wks = Project.ActiveLayer(); // get worksheet with group.dat data if( !wks ) { out_str("Please activate worksheet with group.dat data!"); return; } // plot scatter central plot DataRange dr; dr.Add(wks, 0, "X"); dr.Add(wks, 1, "Y"); GraphPage gp; gp.Create("ScatterCentral"); // create scatter central graph if( !gp ) { out_str("Failed to create scatter central plot!"); return; } GraphLayer gl = gp.Layers(0); int nPlot = gl.AddPlot(dr, IDM_PLOT_SCATTER); // add plot to layer if( nPlot >= 0 ) // if add plot successfully { DataPlot dp = gl.DataPlots(0); dp.SetSymbol(110); // set symbol shape: sphere dp.SetColor(SYSCOLOR_RED); // set color: red gl.Rescale(); } }
Minimum Origin Version Required: Origin 8.1 SR1
This example is used to create a Y error plot. It also changes some formats of the symbols and error bars.
void y_error_plot() { Worksheet wks = Project.ActiveLayer(); // get worksheet with group.dat data if( !wks ) { out_str("Please activate worksheet with group.dat data!"); return; } // plot simple scatter plot DataRange dr; dr.Add(wks, 0, "X"); // X column dr.Add(wks, 1, "Y"); // Y column dr.Add(wks, 3, "ED"); // Error column GraphPage gp; gp.Create("Errbar"); // create error bar if( !gp ) { out_str("Failed to create scatter central plot!"); return; } GraphLayer gl = gp.Layers(0); int nPlot = gl.AddPlot(dr, IDM_PLOT_SCATTER); // add plot to layer if( nPlot >= 0 ) // if add plot successfully { for(int nPlot=0; nPlot<gl.DataPlots.Count(); nPlot++) // set format for plots in the layer { DataPlot dp; switch (nPlot) { case 0: dp = gl.DataPlots(0); // scatter plot dp.SetColor(SYSCOLOR_RED); // set color Column colSize; colSize = wks.Columns(2); // column C dp.SetModifier(COLDESIG_SIZE, colSize); // column C as size Tree trFormat; trFormat.Root.Symbol.Scale.dVal = 2.; // scaling factor trFormat.Root.Symbol.Shape.nVal = 5; // symbol shape: diamond trFormat.Root.Symbol.Interior.nVal = 1; // interior: empty if(0 == dp.UpdateThemeIDs(trFormat.Root)) dp.ApplyFormat(trFormat, true, true); break; case 1: dp = gl.DataPlots(1); // error bar Tree trFormat; trFormat.Root.Line.Color.nVal = SYSCOLOR_BLUE; // set color trFormat.Root.Line.Width.dVal = 2.; // set line width if(0 == dp.UpdateThemeIDs(trFormat.Root)) dp.ApplyFormat(trFormat, true, true); // apply theme tree break; } } gl.Rescale(); } }
Minimum Origin Version Required: Origin 8 SR1
This example is capable of creating a scatter plot with X and Y error bars. The formats of symbols, X and Y error bars are modified too, including symbol shape, size, color, width of error bar, etc..
void xy_error_plot() { Worksheet wks = Project.ActiveLayer(); // get worksheet with group.dat data if( !wks ) { out_str("Please activate worksheet with group.dat data!"); return; } Curve crv(wks, 0, 1); GraphPage gp; gp.Create("Scatter"); // create scatter if( !gp ) { out_str("Failed to create scatter central plot!"); return; } GraphLayer gl = gp.Layers(0); int nScatterPlot = gl.AddPlot(crv, IDM_PLOT_SCATTER); // add plot to layer if( nScatterPlot >= 0 ) // if add plot successfully { Column colXErrBar(wks, 2); // column C int nXErrPlot = gl.AddXErrBar(crv, colXErrBar); // add column C as X error Column colYErrBar(wks, 3); // column D int nYErrPlot = gl.AddErrBar(crv, colYErrBar); // add column D as Y error if( nXErrPlot >= 0 && nYErrPlot >= 0) { for(int nPlot=0; nPlot<gl.DataPlots.Count(); nPlot++) { DataPlot dp; switch (nPlot) { case 0: // set format for scatter plot dp = gl.DataPlots(0); dp.SetColor(SYSCOLOR_RED); // set color Tree trFormat; trFormat.Root.Symbol.Shape.nVal = 5; // set shape: diamond trFormat.Root.Symbol.Interior.nVal = 1; // interior: empty trFormat.Root.Symbol.Size.nVal = 12; // set size: 12 if(0 == dp.UpdateThemeIDs(trFormat.Root)) dp.ApplyFormat(trFormat, true, true); // apply theme format tree break; case 1: // set format for X error bar dp = gl.DataPlots(1); // X error bar Tree trFormat; trFormat.Root.Line.Color.nVal = SYSCOLOR_MAGENTA; // set color trFormat.Root.Line.Width.dVal = 2.; // set line width if(0 == dp.UpdateThemeIDs(trFormat.Root)) dp.ApplyFormat(trFormat, true, true); // apply theme tree break; case 2: // set format for Y error bar dp = gl.DataPlots(2); // Y error bar Tree trFormat; trFormat.Root.Line.Color.nVal = SYSCOLOR_BLUE; // set color trFormat.Root.Line.Width.dVal = 2.; // set line width if(0 == dp.UpdateThemeIDs(trFormat.Root)) dp.ApplyFormat(trFormat, true, true); // apply theme tree break; } } } gl.Rescale(); } }
Minimum Origin Version Required: Origin 8.1 SR1
This example is used to create a bubble plot. Mean while, the sizes and colors of the bubbles are set by existing columns.
void bubble_plot() { Worksheet wks = Project.ActiveLayer(); if( !wks ) { out_str("Pls activate worksheet with group.dat data"); return; } // plot bubble DataRange dr; dr.Add(wks, 0, "X"); // X column dr.Add(wks, 1, "Y"); // Y column GraphPage gp; gp.Create("bubble"); // create bubble plot GraphLayer gl = Project.ActiveLayer(); int nPlot = gl.AddPlot(dr, IDM_PLOT_SCATTER); if( nPlot >= 0 ) // add plot successfully { DataPlot dp = gl.DataPlots(0); Column colSize = wks.Columns(2); dp.SetModifier(COLDESIG_SIZE, colSize); // column C as Size Column colColor = wks.Columns(3); dp.SetModifier(COLDESIG_COLOR, colColor); // column D as Color Map gl.Rescale(); } }