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 atomic graphic object, or any model object.
Specify the type of symbol to use when you call the IDLgrSymbol::Init method.
Specify one of the following values for the symbol type:
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])
You can use an atomic graphic 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 |
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]
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 for details on creating 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 like the following to define a pentagon object contained in a model object, and return the object references.
| Note |
penta.pro, located in the examples/visual subdirectory of the IDL distribution.
;Allow user to set the color and retrieve the object
;references to the symbol, and model objects created.
PRO penta, COLOR=color, SYMBOL=symbol, MODEL=model
;If the color keyword is set, use the specified color.
;Otherwise, use blue.
IF KEYWORD_SET(color) THEN COLOR=color ELSE COLOR=[0,0,255]
;Create a model object.
model = OBJ_NEW('IDLgrModel')
;Create a polygon that takes up most of the domain
;between -1 and 1 in the X and Y directions. Set its color.
symbol = OBJ_NEW('IDLgrPolygon', [-0.8, 0.0, 0.8, 0.4, -0.4], $
[0.2, 0.8, 0.2, -0.8, -0.8], COLOR=color)
;Add the polygon to the model.
model->ADD, symbol
END
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.