3.5.5 Accessing Group Plots Format

Setting Grouped Format of Line + Symbol Plots

Minimum Origin Version Required: Origin8 SR2

This example is used to set grouped format for grouped plots with Line + Symbol type, including line color, line style, symbol shape and symbol interior.

To run this example, please run the following LabTalk first to create the desired graph.

newbook;  // create a new workbook
fname$ = system.path.program$ + "Samples\Curve Fitting\Multiple Gaussians.dat";  // file path
impasc;  // import data file
plotxy iy:=(?,1:end) plot:=202;  // plot line+symbol
void grouped_line_symbol()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
	{
		out_str("Cannot get the graph layer!");
		return;
	}
	
	GroupPlot gplot = gl.Groups(0);
	if(!gplot)
	{
		out_str("Cannot get the group plot!");
		return;
	}
	
	vector<int> vNester;
	
	// the Nester is an array of types of objects to do nested cycling in the group
	vNester.SetSize(4);  // four types of setting to do nested cycling in the group
	vNester[0] = 0;  // cycling line color in the group
	vNester[1] = 3;  // cycling symbol type in the group
	vNester[2] = 2;  // cycling line style in the group
	vNester[3] = 8;  // cycling symbol interior in the group
	
	gplot.Increment.Nester.nVals = vNester;  // set Nester of the grouped plot
	
	int nNumPlots = gl.DataPlots.Count();  // nNumPlots = 4 in this example
	
	vector<int> vLineColor, vSymbolShape, vLineStyle, vSymbolInterior;
	
	// four vectors for setting line color, symbol shape, line style and symbol interior of grouped plots
	vLineColor.SetSize(nNumPlots);
	vSymbolShape.SetSize(nNumPlots);
	vLineStyle.SetSize(nNumPlots);
	vSymbolInterior.SetSize(nNumPlots);
	
	// setting corresponding values to four vectors
	for(int nPlot=0; nPlot<nNumPlots; nPlot++)
	{
		if(nNumPlots>=4)
		{
			switch (nPlot)
			{
				case 0:  // setting for plot 0
					vLineColor[nPlot] = SYSCOLOR_BLUE;
					vSymbolShape[nPlot] = 1;  // square
					vLineStyle[nPlot] = 1;    // dash
					vSymbolInterior[nPlot] = 1;  // open
					break;
				case 1:  // setting for plot 1
					vLineColor[nPlot] = SYSCOLOR_OLIVE;
					vSymbolShape[nPlot] = 3;  // up triangle
					vLineStyle[nPlot] = 2;    // dot
					vSymbolInterior[nPlot] = 2;  // dot center
					break;
				case 2:  // setting for plot 2
					vLineColor[nPlot] = SYSCOLOR_RED;
					vSymbolShape[nPlot] = 5;  // diamond
					vLineStyle[nPlot] = 6;    // short dot
					vSymbolInterior[nPlot] = 5;  // x center
					break;
				default:  // setting for other plot
					vLineColor[nPlot] = SYSCOLOR_CYAN;
					vSymbolShape[nPlot] = 8;  // hexagon
					vLineStyle[nPlot] = 0;    // solid
					vSymbolInterior[nPlot] = 0;  // solid
					break;
			}
		}
	}
	
	Tree trFormat;
	trFormat.Root.Increment.LineColor.nVals = vLineColor;  // set line color to theme tree
	trFormat.Root.Increment.Shape.nVals = vSymbolShape;  // set symbol shape to theme tree
	trFormat.Root.Increment.LineStyle.nVals = vLineStyle;  // set line style to theme tree
	trFormat.Root.Increment.SymbolInterior.nVals = vSymbolInterior;  // set symbol interior to theme tree
	
	if(0 == gplot.UpdateThemeIDs(trFormat.Root) )    
	{
		bool bb = gplot.ApplyFormat(trFormat, true, true);    // apply theme tree
	}
}

Setting Colors for Grouped Bars

Minimum Origin Version Required: Origin 7.5

The following example is used to set the colors of grouped bars. The colors are customized according to the column names. So, you can specify the unique color to the bar created from the column with the specified name. As the example shows, the bar created from the column named "N" will always have the red color.

To run this example, please run the following LabTalk script first to create the desired graph.

win -n wks ColumnColor;   // create a new window
wks.addcol(A);            // add column named A
ColumnColor_A[1] = 1;     // set cell one with 1;
wks.col1.type = 4;        // set to X column
wks.addcol(B);
ColumnColor_B[1] = 2;
wks.addcol(O);
ColumnColor_O[1] = 3;
wks.addcol(P);
ColumnColor_P[1] = 4;
wks.addcol(C);
ColumnColor_C[1] = 5;
wks.addcol(N);
ColumnColor_N[1] = 6;
wks.addcol(D);
ColumnColor_D[1] = 7;
worksheet -s 1 1 wks.ncols 1;   // select cell one of all columns
worksheet -p 203 column;        // make grouped bar plots;
void bar_color_map()
{
	GraphLayer gl = Project.ActiveLayer();   // get active graph layer
	if(!gl)
	{
		out_str("Cannot get the active graph layer!" );
		return;
	}

	GroupPlot gpl = gl.Groups(0);   // get first grouped plots
	
	vector<int> vcColors;  
	int nPlotCount = gl.DataPlots.Count();  // get number of plots
	vcColors.SetSize(nPlotCount);      // set vector size
	for(int nColor=0; nColor<nPlotCount; nColor++)   // set color vector according to the column name
	{
		DataPlot dp = gl.DataPlots(nColor);	          // get dataplot
		
		string strDatasetName = dp.GetDatasetName();
		int nStart = strDatasetName.Find('_');     // find delimited "_", between workbook name and colcumn name 
		int nEnd = strDatasetName.Find('@');     // find delimited "@", between column name and worksheet index
		
		string strColName;
		
		// get column name
		if(nEnd == -1)   // workbook contains only one worksheet
			strColName = strDatasetName.GetToken(1, '_');        
		else            // workbook contains more than one worksheet
			strColName = strDatasetName.Mid(nStart+1, nEnd-nStart-1);
		
		if(0 == strColName.Compare("C"))                 // set color value one by one
			vcColors[nColor] = 0;       // 0 = black
		else if(0 == strColName.Compare("N"))
			vcColors[nColor] = 1;       // 1 = red
		else if(0 == strColName.Compare("O"))
			vcColors[nColor] = 2;       // 2 = green
		else if(0 == strColName.Compare("P"))
			vcColors[nColor] = 3;       // 3 = blue
		else
			vcColors[nColor] = 4;       // 4 = cyan
	}
	
	gpl.Increment.BackgroundColor.nVals = vcColors;  // set increment colors
}

Setting Offset Individually for Grouped Plots

This example is used to set the offset of the grouped plot individually.

Please run the following LabTalk script to create the desired graph first.

newbook;  // create a new workbook
fname$ = system.path.program$ + "Samples\Graphing\Group.DAT";  // file path
impasc;  // import data file
plotxy iy:=(?, 1:end) plot:=200;  // plot line
void set_offset(int nPlotLTIndex, double xOffset, double yOffset)
{
	GraphLayer gl = Project.ActiveLayer();  // get the active graph layer
	if(!gl)
	{
		out_str("Please activate a graph!");
		return;
	}
	GroupPlot grPlot = gl.Groups(0);  // get the first grouped plot
	if(!grPlot)
	{
		out_str("Invalid grouped plot!");
		return;
	}
	if(nPlotLTIndex <= 0 || nPlotLTIndex > grPlot.GetCount())
	{
		out_str("Invalid plot index!");
		return;
	}
	
	Tree trFormat;
	trFormat.Root.Stack.Offset.dVal = 4;  // set Stack to Individual
	trFormat.Root.Stack.X.dVal = 1;  // enable X offset
	trFormat.Root.Stack.Y.dVal = 1;  // enable Y offset
	if(0 == gl.UpdateThemeIDs(trFormat.Root))
	{
		bool bRet = gl.ApplyFormat(trFormat, true, true);  // enable settings of offset individually
		if(bRet)
		{
			DataPlot dp = grPlot.GetDataPlot(nPlotLTIndex - 1);  // get the plot in the layer
			string strPlotName = dp.GetDatasetName();  // get the plot name
			string strLTPlotXOffset, strLTPlotYOffset;  
			strLTPlotXOffset.Format("set %s -sx %f;", strPlotName, xOffset);  // set x offset of the plot
			strLTPlotYOffset.Format("set %s -sy %f;", strPlotName, yOffset);  // set y offset of the plot
			gl.LT_execute(strLTPlotXOffset + strLTPlotYOffset);  // execute the LabTalk command
		}
	}
}

To set the offset of the 2nd plot in x and y direction with 2 and 3 respectively, run

set_offset 2 2 3;

Setting special point format of one plot of group plots

This example shows how to access theme of one plot in group.

To run this example, please

  1. select 3 columns(XYY) to plot a 2d scatter graph
  2. select one data point of the 2nd plot and double click to open Plot Details dialog
  3. go to label tab, check enable to show the label for this point
void test_group_plot_special_point_format()
{
	GraphLayer gl = Project.ActiveLayer();
	int		nCount = gl.DataPlots.Count();
	DataPlot dp = gl.DataPlots(nCount > 1 ? 1 : 0);
	
	//System variable @PGT: theme for plot in group, 
	//1 for using group theme (default, old behavior)
	//0 for using plot's own theme
	LTVarTempChange pgt("@PGT", 0);
	
	Tree tr;
	tr = dp.GetFormat(FPB_ALL, FOB_ALL, TRUE, TRUE);
	tr.Root.Points.Point1.Label.Size.dVal = 30;
	tr.Root.Points.Point1.Label.AutoFace.nVal = 0;
	tr.Root.Points.Point1.Label.Face.nVal = 2;
	dp.UpdateThemeIDs(tr.Root);
	dp.ApplyFormat(tr, true, true);
}