|
|
|
|
Conversion to PythonHere we convert several CIAO 3 plots to the Python interface of CIAO 4. The examples use a text file, sample.txt, whose contents are # x y dy 1 10 3 2.5 20 5 5 17 5 9 21 5.5 12 -5 3 20 25 7 40 80 11 The CIAO 4 examples assume that you have not set the CHIPS_SCRIPT_LANG environment variable set to slang, or changed the chips.shell preference setting in ~/.chips.rc from python. For further information see the Starting ChIPS thread. A complete list of all the CIAO 3.4 ChIPS commands and their Python equivalents in CIAO 4 is also available. A simple plotThis example illustrates how you convert several common CIAO 3.4 commands, including CURVE, LABEL, LINE, XLABEL, YLABEL, TITLE, and PRINT.
CIAO 3 command language
unix% chips
Welcome to ChIPS, version CIAO 3.4
Copyright (C) 1999-2003, Smithsonian Astrophysical Observatory
chips> curve "sample.txt" x 1 y 2
chips> sym square
chips> label 5 70 "Main sample (\beta<0.5)"
chips> line -100 -100 100 100
chips> line red
chips> line dash
chips> xlabel "r (kpc)"
chips> ylabel "\alpha / \alpha_0"
chips> title "Comparison plot 1"
chips> label size 1.2
chips> xlabel size 1.2
chips> ylabel size 1.2
chips> title size 1.2
chips> print postfile plot1.ps
chips> info
Drawing Area #1 << CURRENT DRAWING AREA
(Location: 0.15 0.9 0.1 0.9)
(Limits : -0.95 41.95 -9.25 84.25)
(Axes : fouraxes color: defaultcolor width: 1)
Curve #1 /data/chips/sample.txt
SYMBOL: defaultcolor square
CONNECTOR: noline << CURRENT CURVE
Label #1 "Main sample (\beta<0.5)" Location: (5, 70) Size: 1.2 << CURRENT LABEL
Line #1 Starting at (-100, -100) ending at (100, 100) Color: red << CURRENT LINE
where bold text in the output from INFO is used to indicate text in reverse video. CIAO 4 Python version
unix% chips
chips-1> add_curve("sample.txt[cols x,y]",["line.style","none"])
chips-2> set_curve(["symbol.style","square","symbol.fill",0])
chips-3> add_label(5,70,r"Main sample (\beta<0.5)")
chips-4> add_line (0,0,40,40,["extend","both","color","red","style","longdash"])
chips-5> set_plot_xlabel("r (kpc)")
chips-6> set_plot_ylabel(r"\alpha / \alpha_0")
chips-7> set_plot_title("Comparison plot 1")
chips-8> set_label(["size",18])
chips-9> set_axis(["label.size",18])
chips-10> set_plot(["title.size",18])
chips-11> print_window("plot1")
chips-12> print info()
Window [win1]
Frame [frm1]
Plot [plot1] (0.15,0.15) .. (0.90,0.90)
Border bottom [bx1] top [bx2] left [by1] right [by2]
X Axis [ax1]
Y Axis [ay1]
Curve [crv1]
Label [lbl1]
Line [line1]
chips-13> get_plot_xrange()
[-0.95000000000000018, 41.950000000000003]
chips-14> get_plot_yrange()
[-9.25, 84.25]
chips-15> print get_line()
color = red
depth = 100
extend = 3
id = None
stem = None
style = 5
thickness = 1.0
Two plots: plotting data from a file and from arraysThis example show how you convert the SPLIT and RELSIZE commands, as well as the curve() S-Lang function.
Note that the blue dotted line connecting the curve is not drawn to the point that has y < 0 in CIAO 4.0, due to the logarithmic scale used for the Y axis, whereas it was in CIAO 3.4 (or at least a line was drawn vertically down). CIAO 3 command language
unix% chips
Welcome to ChIPS, version CIAO 3.4
Copyright (C) 1999-2003, Smithsonian Astrophysical Observatory
chips> curve "sample.txt" x 1 y 2 e 3
chips> log y
chips> limits y 6 auto
chips> sym magenta
chips> err red
chips> simpleline
chips> blue
chips> longdash
chips> split 2
chips> split gap 0.1
chips> relsize 2
chips> d 2
chips> x = [1:10:0.1];
chips> y = sin(x);
chips> () = curve(x,y);
chips> simpleline
chips> sym none
chips> magenta
chips> xlabel x_2
chips> ylabel y_2
chips> xlabel size 1.6
chips> ylabel size 1.6
chips> xlabel magenta
chips> ylabel magenta
chips> d 1
chips> xlabel \eta
chips> ylabel "rate (count s^{-1})"
chips> xlabel size 1.6
chips> ylabel size 1.6
chips> print postfile plot2.ps
CIAO 4 S-Lang version
unix% chips
chips-1> add_curve("sample.txt[cols x,y,dy]",["line.style","none"])
chips-2> log_scale(Y_AXIS)
chips-3> ci = ChipsCurve()
chips-4> ci.err.style = "cap"
chips-5> ci.err.color = "red"
chips-6> ci.line.style = "longdash"
chips-7> ci.line.color = "blue"
chips-8> ci.symbol.color = "magenta"
chips-9> set_curve(ci)
chips-10> split(2,1,0.1)
chips-11> adjust_grid_yrelsize (1, 2)
chips-12> x = numpy.arange(1,10,0.1)
chips-13> y = numpy.sin(x)
chips-14> add_curve(x,y,["line.color","magenta","symbol.style","none"])
chips-15> set_plot_xlabel("x_2")
chips-16> set_plot_ylabel("y_2")
chips-17> set_axis(["label.size",18,"label.color","magenta"])
chips-18> current_plot("plot1")
chips-19> set_plot_xlabel(r"\eta");
chips-20> set_plot_ylabel("rate (count s^{-1})")
chips-21> set_axis(["label.size",18])
chips-22> set_xaxis(["offset.perpendicular",35])
chips-23> print_window("plot2")
Preferences and HistogramsThis example show how you set preferences and draw histograms (i.e. how to convert the STEP command).
The four major differences in these plots are:
CIAO 3 command languageunix% chips Welcome to ChIPS, version CIAO 3.4 Copyright (C) 1999-2003, Smithsonian Astrophysical Observatory chips> chips.symbolstyle = _chips->soliddiamond chips> chips.symbolcolor = _chips->blue chips> chips.curvecolor = _chips->red chips> chips.curvestyle = _chips->step chips> curve sample.txt x 1 y 2 chips> longdash CIAO 4 Python version
unix% chips
chips-1> pr = ChipsHistogram()
chips-2> pr.symbol.style = "diamond"
chips-3> pr.symbol.fill = True
chips-4> pr.symbol.color = "blue"
chips-5> pr.line.color = "red"
chips-6> set_preferences(pr)
chips-7> add_histogram("sample.txt[cols x,y]")
chips-8> set_histogram(["line.style","longdash","fill.visible",1,"fill.color","green"])
If you only wanted to override the preferences for the add_histogram call - so that future calls use the original preference settings - then you would say add_histogram("sample.txt[cols x,y]",pr)instead of lines 6 and 7 above. |
![]() |
The Chandra X-Ray
Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA. Email: cxcweb@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2004. All rights reserved. |