Greek and other Symbols in Coyote Graphics [message #80968] |
Fri, 27 July 2012 13:12  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Folks,
As I was answering a question about Coyote Graphics this
morning, it suddenly occurred to me that I knew how to
fix one of the biggest annoyances in the Coyote Graphics
system for me. This is the problem of wanting to use
a Greek or other symbol (an Angstrom symbol, for example)
in a plot or axis title in a command that I've put into
the resizeable graphics window, cgWindow.
I can certainly specify these symbols using cgSymbol, but
the problem is that these symbols need to be evaluated
at run-time, and when you use them as keywords the value
returned by cgSymbol is hard-coded as the keyword value for the
command execution. But, since the symbol code is different
for PostScript than it is for the display, it makes it
very difficult to get PostScript output from cgWindow.
My solution was the clunky "alternative" keyword and
parameter keywords described here:
http://www.idlcoyote.com/cg_tips/kwexpressions.php
You will be happy to hear this nonsense is a thing
of the past! :-)
This morning it occurred to me that I can use the same
"escape sequences" used by Function Graphics to specify
symbols in my Coyote Graphics routines. These escape
sequences prepend a "$\" to the symbol you want to
call with cgSymbol, and append a closing "$".
So, here is the clunky way a cgPlot command would have to be
constructed currently to display properly in a cgWindow
and in an output file with a mu and angstrom symbol:
cgPlot, cgDemoData(1), /Window, $
XTitle='Length (' + cgSymbol('mu') + M)', $
YTitle='Distance (' + cgSymbol('Angstrom') + ')', $
ALT_KEYWORDS={xtitle:'Length (' + cgSymbol('mu', /PS) + M)', $
ytitle:'Distance ('+ cgSymbol('Angstrom', /PS)+')'}
And here is the new way to do this:
cgPlot, cgDemoData(1), /Window, $
XTitle='Length ($\mu$M)', $
YTitle='Distance ($\Angstrom$)'
Quite a bit simpler, yes? :-)
You can find an updated program here with a new ReplaceEscapeSequences
method:
http://www.idlcoyote.com/programs/cgcmdwindow__define.pro
I'll write an article about this change shortly, but this will
work for any of the symbols available in cgSymbol:
http://www.idlcoyote.com/idldoc/cg/cgsymbol.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|