★ IDL 8.0: a new graphics interface
posted Thu 12 Aug 2010 by Michael Galloy under IDL, iTools, Object graphicsIDL 8.0 introduces an entirely new graphics interface. Currently, there is no name for this system except Graphics (am I supposed to say it capitalized when talking?), so I will refer to them as function graphics because all the routines are functions instead of procedures as in most direct graphics and iTools graphics routines. This new system is easy to use, interactive, programmatically accessible, and fairly complete even in this first release.
I can only just skim the surface of the capabilities of function graphics in this post. See the online help for more details.
To create a plot using function graphics, do:
IDL> p = plot(findgen(10), color=[255, 0, 0])
The plot can be annotated from the GUI interface, but it can also be modified via the return value p
, an object which represents the newly created plot. You can get and set properties of the graphics object easily:
IDL> p.color = 'blue' ; or you could use [0, 0, 255]
The plot line automatically changes to blue.
IDL> print, p.color
0 0 255
From the command line, to find all the available properties of one of the graphics object returned from a function graphics routine, just print it:
IDL> print, p
PLOT <21317>
ANTIALIAS = 1
ASPECT_RATIO = 0.0000000
ASPECT_Z = 0.0000000
BACKGROUND_COLOR = 255 255 255
COLOR = 255 0 0
DEPTH_CUE = 0.00000 0.00000
[etc, rest of output omitted for brevity]
By the way, if you want to refer to colors by name in other uses in IDL, you can use the new !color
system variable:
IDL> print, !color.blue
0 0 255
You can see a listing of all of the color names available by using HELP
on !color
:
IDL> help, !color, /structures
** Structure !COLOR, 147 tags, length=441, data length=441:
ALICE_BLUE BYTE Array[3]
ANTIQUE_WHITE BYTE Array[3]
AQUA BYTE Array[3]
AQUAMARINE BYTE Array[3]
[etc, rest of output omitted for brevity]
Note that function graphics can be used programmatically without any graphics windows appearing on the screen:
IDL> c = contour(dist(200), /buffer)
IDL> c->save, 'contour.png'
See the online help on a particular graphics object type to see its available methods, but most seem to have close
, convertCoord
, copyWindow
, getSelect
, order
, print
, refresh
, rotate
, save
, scale
, select
, and translate
.
The WIDGET_WINDOW
routine provides a way to add a function graphics window to a widget application.
One of my favorite features in the new graphics API is that LaTeX escape sequences are built-in! For example,
IDL> p = plot(findgen(10), title='Some formula: $\mu = \epsilon^2 + \tau$')
(UPDATE: there is a TEX2IDL
routine in the IDL distribution now that can be used independently of the function graphics routines.)
The following functions are part of the function graphics API: BARPLOT
, COLORBAR
, LEGEND
, CONTOUR
, ERRORPLOT
, IMAGE
, MAP
, MAPCONTINENTS
, MAPGRID
, PLOT
, PLOT3D
, POLARPLOT
, SURFACE
, VECTOR
, AXIS
, ELLIPSE
, POLYGON
, POLYLINE
, STREAMLINE
, TEXT
, and WINDOW
.
There is much, much more to be said about function graphics, but hopefully this will get you started exploring. It will take more time to actually do some work using it to determine its shortcomings, but I think it is the most important feature of IDL 8.0.
Stay tuned for one last wrap-up article about IDL 8.0.
August 12th, 2010 at 8:24 pm
Hi Mike,
Ack! You used a “->” instead of a “.” for the “save” method call. That “->” is sooo old school.
Great set of posts, by the way. Keep it up!
-Chris
August 12th, 2010 at 8:31 pm
Michael,
1) you write that a colour could be specified by a RGB triple. Can it also be called by it’s decomposed value, ie Blue would be 16711680. Just in case that was, for some reason, convenient.
2) I seem to recall seeing that IDL 8.0 has introduced a void context. So that would presumably mean these new graphics functions can still be called as procedures:
plot,findgen(10)
So that ITT’s goal of legacy compatibility is maitained. However, the syntax for procedures and functions are different (use of brackets)…
August 13th, 2010 at 9:26 am
@Chris I’m not sure what to make of the using the “.” operator for method calls. I like having a difference between method calls and property/instance variable access. I think it will probably be more comfortable for some (I know the “->” was odd for me when I started IDL), but I will probably keep using “->” now that I am comfortable with it.
August 13th, 2010 at 9:32 am
@Stewart 1) a color can be specified via an index in two ways:
or
makes the plot blue. Yes, that’s not a typo,
p.color = 255
is blue, the color indices are reversed from standard IDL notation, but the same as other color notations like CSS/HTML now.2) You can ignore a function return value by assigning it to
!null
, likeAugust 13th, 2010 at 10:51 am
Also, note that there is now a TEX2IDL routine in the IDL distribution which can be used independently of the function graphics routines.
October 13th, 2011 at 3:52 pm
Michael;
Thanks for tying the pieces together for me. I’ve been trying to figure out how to use the new graphics functions inside a GUI of my own creation, and the IDL help system is a nightmare for figuring that out. It seems that all of the old guides haven’t been kept in version 8, so I can’t even find the guide, and read through it. Instead, I’m presented with an alphabetical list of topics, and have no idea where to dive in. This post gives me the right starting place (widget_window!)
October 13th, 2011 at 4:53 pm
I’m glad this got you started. I have no idea why they removed half the online help!