comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Adding Text/Equations to Plots
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Adding Text/Equations to Plots [message #65703 is a reply to message #65702] Mon, 16 March 2009 12:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Heather writes:

> I'm hoping someone can help me figure out a way to add equations to a
> plot. I used POLY_FIT to find the coefficients of a line for my data,
> and plotted that line. I really want to add the equation of that line
> to my plot.
>
> I thought I could use legend.pro (a routine I found at
> http://astro.uni-tuebingen.de/software/idl/astrolib/plot/leg end.pro
> that I am already calling in my routine anyhow), but that requires the
> input "items" be a string. And I couldn't figure out how to create a
> string that would call the elements of the array in which the
> coefficients are.
> (This is what I tried:
> IDL> numbers=findgen(10)
> IDL> string="This is a number: numbers(6)"
> IDL> print, string
> This is a number: numbers(6)
>
> Clearly not what I want. And I can't do something like:
> IDL> string1="This is a number: "
> IDL> print, string1, numbers(6)
> This is a number: 6.00000
>
> because what it will actually look like to the legend.pro routine is:
> IDL> string2="This is a number: " numbers(6)
>
> string2="This is a number: " numbers(6)
> ^
> % Syntax error.
>
> Any advice would be greatly appreciated, but I'm fairly new to the
> world of IDL, so please use "simple" explanations!

"Simple explanations"!? Do you see what the world is
coming to?

OK, here is a simple explanation. What you want to
do is concatenate strings. That is a big word that
means "string them together like beads on a string".
Whoops! Two different meanings of "string" here. :-(

OK, looks like you maybe know what a string is in
computer-speak. What you need to know, in a nutshell,
is how to turn a number into a string. You do that,
believe it or not, with the STRING command. (Do you
see now how even simple explanations trip themselves up?)

Here is an example:

IDL> var_1 = 'dog'
IDL> number = 8
IDL> var_2 = 'something'
IDL> mystring = var_1 + ' ' + StrTrim(number,2) + ' ' + var_2
IDL> print, mystring
dog 8 something

If you are really lucky, you can turn numbers into strings
with STRTRIM. If you are unlucky, you need to use the STRING
command, with (there is a good chance of this) the FORMAT
keyword set to a likely format.

number = 3.45096754
aString = String(number, FORMAT='(F5.2)')

The program Number_Formatter is handy for this sort of thing:

http://www.dfanning.com/programs/number_formatter.pro

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Adding Text/Equations to Plots
Next Topic: Using contour in postscripts produces a "stripe" effect?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 02:37:53 PDT 2025

Total time taken to generate the page: 1.12169 seconds