Symbol Objects

Objects of the IDLgrSymbol class are used to display individual data points, either in an IDLgrPlot object or an IDLgrPolyline object. You can create symbol objects that display one of seven pre-defined symbols, any visualization object, or any model object.

Creating Symbol Objects

Specify the type of symbol to use when you call the IDLgrSymbol::Init method.

To Use a Pre-defined Symbol

Specify one of the following values for the symbol type:

1

Plus sign (the default)

2

Asterisk

3

Period

4

Diamond

5

Triangle

6

Square

7

X

For example, to create a symbol object using a red triangle for the symbol, use the following statement:

mySymbol = OBJ_NEW('IDLgrSymbol', 5, COLOR=[255,0,0]) 

To Use a Graphic Object as a Symbol

You can use an visualization object or a model object as a symbol. For best results, create an object that fills the domain between –1 and 1 in all directions. For example, the following statements create a polygon object in the shape of a pentagon and define a symbol object to use the polygon:

pentagon=OBJ_NEW('IDLgrPolygon', [-0.8,0.0,0.8,0.4,-0.4], $ 
    [0.2,0.8,0.2,-0.8,-0.8], COLOR=[0,0,255]) 
mySymbol = OBJ_NEW('IDLgrSymbol', pentagon) 

Note that we create the pentagon to fit in the plane between –1 and 1 in both the X and Y directions. We could also have created the pentagon to fit in a unit square and then scaled it to fit the domain between –1 and 1.

For example:

pentagon=OBJ_NEW('IDLgrPolygon', [0.1,0.5,0.9,0.7,0.3], $ 
   [0.6,0.9,0.6,0.1,0.1], COLOR=[0,0,255]) 
symModel = OBJ_NEW('IDLgrModel') 
symModel->Add, pentagon 
symModel->Scale, 2, 2, 1 
symModel->Translate, -1, -1, 0 
mySymbol = OBJ_NEW('IDLgrSymbol', symModel) 
 

Note
We create the symbol object to use the model object rather than the polygon object. Using a model object as a symbol allows you to apply transformations to the symbol even after it has been created.

Setting Size

By default, symbols extend one unit to each side of the data point they represent. Set the SIZE property of the symbol object to a two-element vector that describes the scaling factor in X and Y to apply to the symbol to change the size of the symbols that are rendered. For example, to scale a symbol so that it extends one tenth of a unit to each side of the data point, use the statement:

mySymbol->SetProperty, SIZE=[0.1, 0.1] 

Setting Color

If you are using a pre-defined symbol, you can set its color using the COLOR property of the symbol object. If you are using a graphic object as a symbol, the symbol's color is determined by the color of the graphic object and the setting of the COLOR property of the symbol object itself is ignored. For example, the following statements create a symbol object that uses a red triangle:

mySymbol = OBJ_NEW('IDLgrSymbol', 5, COLOR=[255,0,0]) 

See "IDLgrSymbol" (IDL Reference Guide) for details on creating symbol objects.

Using Symbol Objects

To use a symbol, set the SYMBOL property of an IDLgrPlot or IDLgrPolyline object equal to the symbol object reference:

myPlot->SetProperty, SYMBOL=mySymbol 

Suppose you wish to create a symbol object using the pentagon we created above. Suppose also that you wish to be able to use the pentagon code in more than one instance, and would like to be able to make changes to the pentagon object's color, size, and orientation. You might create a procedure to define a pentagon object contained in a model object, and return the object references.

Example Code
See file penta.pro, located in the examples/doc/objects subdirectory of the IDL distribution to view the source code for this example. Run the example procedure by entering penta at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT penta.pro.

Once you have compiled the penta procedure, call it with the SYMBOL and MODEL keywords set equal to named variables that will contain the object references of the model and polygon objects:

PENTA, SYMBOL=sym, MODEL=symmodel 

Next, create a symbol object using the pentagon:

mySymbol = OBJ_NEW('IDLgrSymbol', symmodel) 

Now, create a plot object using the pentagon as the plot symbol:

myPlot = OBJ_NEW('IDLgrPlot', FINDGEN(10), SYMBOL=mySymbol) 

Next, display the plot:

myView = OBJ_NEW('IDLgrView', VIEWPLANE_RECT=[0,0,10,10]) 
myModel = OBJ_NEW('IDLgrModel') 
myView->Add, myModel 
myModel->Add, myPlot 
myWindow = OBJ_NEW('IDLgrWindow') 
myWindow->Draw, myView 

Note that the plotting symbols are larger than you might wish. Try making them smaller:

mySymbol->SetProperty, SIZE=[0.2,0.2] 
myWindow->Draw, myView 

Or, create the following procedure to spin the pentagons around the z-axis (enter .RUN at the command prompt, followed by these statements):

PRO SPIN, model, view, window, steps 
FOR i = 0, steps do begin 
    model->Rotate, [0,0,1], 10 
    window->Draw, view 
END 
END 

After compiling the SPIN procedure, call it from the command line and watch the pentagons spin:

SPIN, symmodel, myView, myWindow, 100 

While it is unlikely that you will wish to create spinning plot symbols, this example demonstrates one of the key advantages of IDL Object Graphics over IDL Direct Graphics—once created, graphics objects can be easily manipulated in a variety of ways without the need to recreate the entire graph or image after each change.