Angstrom and other Astronomical Symbols in Python

Like many others, I’ve began moving over to Python for my plotting and high-level programming, mainly out of frustration with IDL’s license issues. Below is a collection of Python stuff that may be useful for astronomers. It’s published here as my own on-line archive of information, to be added to over time, but since it may turn out to be useful for others I’ve left it publicly viewable.

Doing an Angstrom symbol for axis titles in plots:

r’$\AA$’

Essentially, it is just the latex code with an r prefix. So, for lambda, one would do

r’$\lambda$’

and so on for other greek characters. Although the experts on stackoverflow say the r prefix is needed, in my experience things seem to work just fine in matplotlib without the prefix.

Solar symbol:

‘$\odot$’

Solar mass symbol:

‘$M_{\odot}$’

Saving a plot as PDF:

from matplotlib.backends.backend_pdf import PdfPages

doc = PdfPages(‘filename1.pdf’)

plot code …

doc.savefig()

doc.close()

Saving a plot as PS

import matplotlib
matplotlib.use(‘ps’)

plot code …

plt.savefig(‘fig1.ps’,dpi=250, transparent=True)

Posted in Uncategorized | Tagged , , , , , , , , | 1 Comment

Angstrom character and other astronomical stuff for IDL

IDL, short for Interactive Data Language, is a programming language used for data analysis. It is popular in particular areas of science, such as astronomy, and is hugely powerful and versatile.  That said, getting IDL to produce plots and graphics to look exactly how you want them to look is often tricky — especially when you want labels that include arcane units, such as the Angstrom (Å), or when you want to use super- or sub-script.

Here is a collection of information that may be useful to astronomers (etc.) who use IDL.


IDL fonts

!3 Simplex Roman (default) !12 Simplex Script
!4 Simplex Greek !13 Complex Script
!5 Duplex Roman !14 Gothic Italian
!6 Complex Roman !15 Gothic German
!7 Complex Greek !16 Cyrillic
!8 Complex Italian !17 Triplex Roman
!9 Math Font !18 Triplex Italian
!10 Special Characters !20 Misc
!11 Gothic English !X Revert to entry font

Plotting Symbols

>plot,(x,)y,psym=n

0 joined up
1 Plus Sign (+)
2 Asterisk (*)
3 Dot (.)
4 Diamond
5 Triangle
6 Square
7 Cross (x)
8 User Defined (see USERSYM procedure)
9 Undefined
10 Histogram mode. Horizontal and vertical lines connect the plotted points, as opposed to the normal method of connecting points with straight lines.

To get non-default plot symbols, use PLOTSYM:
>plotsym, psym, [psize, /fill]

PSYM – The following integer values of PSYM will create the corresponding plot symbols
0 circle
1 downward arrow (upper limit), base of arrow begins at plot value
2 upward arrow (lower limt)
3 5 pointed star
4 triangle
5 upside down triangle
6 left pointing arrow
7 right pointing arrow
8 square (custom)
9 Undefined

Symbols in IDL text strings, e.g. plot axis titles

ANGSTROM:-
angstrom = '!6!sA!r!u!9 %!6!n' (to create the symbol)
angstrom = '!3' + STRING(197B) + '!X' (to use octal notation)
then just use it like…
XYOUTS, 0.5, 0.5, /Normal, CharSize=2.0, 'Symbol: ' + angstrom

or for e.g. plot title like “Wavelength (A)”
'Wavelength (!3' + STRING(197B) + '!X)'

SOLAR SYMBOL:-
!D!9n!3!N

GREEK LETTERS:-
!7 is the Greek character set and !3 is the standard character set.
e.g. H beta is H!7b!3

SUPERSCRIPT/SUBSCRIPT:-

!E or !U = superscript (bold one is better)
!I or !D = subscript
!N = back to normal

IDL Colour Tables

>LoadCT,n

0 B-W LINEAR 14 STEPS 28 Hardcandy
1 BLUE/WHITE 15 STERN SPECIAL 29 Nature
2 GRN-RED-BLU-WHT 16 Haze 30 Ocean
3 RED TEMPERATURE 17 Blue – Pastel – Red 31 Peppermint
4 BLUE/GREEN/RED/YELLOW 18 Pastels 32 Plasma
5 STD GAMMA-II 19 Hue Sat Lightness 1 33 Blue-Red
6 PRISM 20 Hue Sat Lightness 2 34 Rainbow
7 RED-PURPLE 21 Hue Sat Value 1 35 Blue Waves
8 GREEN/WHITE LINEAR 22 Hue Sat Value 2 36 Volcano
9 GRN/WHT EXPONENTIAL 23 Purple-Red + Stripes 37 Waves
10 GREEN-PINK 24 Beach 38 Rainbow18
11 BLUE-RED 25 Mac Style 39 Rainbow + white
12 16 LEVEL 26 Eos A 40 Rainbow + black
13 RAINBOW 27 Eos B

Trigonometry

the system variable !DTOR converts degrees to radians when multiplying, for example:
IDL> print, sin(45.0*!DTOR)

Misc

The command TVLCT,R,G,B,\GET loads the current color table into the variables R, G and B. You can then manipulate these variables to change the color table. For example, the following code segment will reverse the color table.
IDL> LOADCT,3 ;Load the Red Temperature color table
IDL> TVLCT,R,G,B,/GET ;Put the table into IDL variables
IDL> RR=REVERSE(R)
IDL> GG=REVERSE(G)
IDL> BB=REVERSE(B)
IDL> TVLCT,RR,GG,BB ;Load the reversed colors

DL fonts (for use in titles etc.)

!3 Simplex Roman (default) !12 Simplex Script
!4 Simplex Greek !13 Complex Script
!5 Duplex Roman !14 Gothic Italian
!6 Complex Roman !15 Gothic German
!7 Complex Greek !16 Cyrillic
!8 Complex Italian !17 Triplex Roman
!9 Math Font !18 Triplex Italian
!10 Special Characters !20 Misc
!11 Gothic English !X Revert to entry font

Plotting Symbols

>plot,(x,)y,psym=n

0 joined up
1 Plus Sign (+)
2 Asterisk (*)
3 Dot (.)
4 Diamond
5 Triangle
6 Square
7 Cross (x)
8 User Defined (see USERSYM procedure)
9 Undefined
10 Histogram mode. Horizontal and vertical lines connect the plotted points, as opposed to the normal method of connecting points with straight lines.

To get non-default plot symbols, use PLOTSYM:
>plotsym, psym, [psize, /fill]

PSYM – The following integer values of PSYM will create the corresponding plot symbols
0 circle
1 downward arrow (upper limit), base of arrow begins at plot value
2 upward arrow (lower limt)
3 5 pointed star
4 triangle
5 upside down triangle
6 left pointing arrow
7 right pointing arrow
8 square (custom)
9 Undefined

Symbols in IDL text strings, e.g. plot axis titles

ANGSTROM:-
angstrom = '!6!sA!r!u!9 %!6!n' (to create the symbol)
angstrom = '!3' + STRING(197B) + '!X' (to use octal notation)
then just use it like…
XYOUTS, 0.5, 0.5, /Normal, CharSize=2.0, 'Symbol: ' + angstrom

or for e.g. plot title like “Wavelength (A)”
'Wavelength (!3' + STRING(197B) + '!X)'

SOLAR SYMBOL:-
!D!9n!3!N (thanks to Magda for finding that)

GREEK LETTERS:-
!7 is the Greek character set and !3 is the standard character set.
e.g. H beta is H!7b!3

SUPERSCRIPT/SUBSCRIPT:-

!E or !U = superscript (bold one is better)
!I or !D = subscript
!N = back to normal

IDL Colour Tables

>LoadCT,n

0 B-W LINEAR 14 STEPS 28 Hardcandy
1 BLUE/WHITE 15 STERN SPECIAL 29 Nature
2 GRN-RED-BLU-WHT 16 Haze 30 Ocean
3 RED TEMPERATURE 17 Blue – Pastel – Red 31 Peppermint
4 BLUE/GREEN/RED/YELLOW 18 Pastels 32 Plasma
5 STD GAMMA-II 19 Hue Sat Lightness 1 33 Blue-Red
6 PRISM 20 Hue Sat Lightness 2 34 Rainbow
7 RED-PURPLE 21 Hue Sat Value 1 35 Blue Waves
8 GREEN/WHITE LINEAR 22 Hue Sat Value 2 36 Volcano
9 GRN/WHT EXPONENTIAL 23 Purple-Red + Stripes 37 Waves
10 GREEN-PINK 24 Beach 38 Rainbow18
11 BLUE-RED 25 Mac Style 39 Rainbow + white
12 16 LEVEL 26 Eos A 40 Rainbow + black
13 RAINBOW 27 Eos B

Link to see Examples
Trigonometry

the system variable !DTOR converts degrees to radians when multiplying, for example:
IDL> print, sin(45.0*!DTOR)

Misc

The command TVLCT,R,G,B,\GET loads the current color table into the variables R, G and B. You can then manipulate these variables to change the color table. For example, the following code segment will reverse the color table.
IDL> LOADCT,3 ;Load the Red Temperature color table
IDL> TVLCT,R,G,B,/GET ;Put the table into IDL variables
IDL> RR=REVERSE(R)
IDL> GG=REVERSE(G)
IDL> BB=REVERSE(B)
IDL> TVLCT,RR,GG,BB ;Load the reversed colors

Posted in Uncategorized | Tagged , , , , , , , | 1 Comment