|
|
|
|
Gallery: Overplotting curves (Python)ExamplesTwo curves in the same plotA plot can contain multiple objects; in this example we show how to add a second curve to a plot and to annotate it with both a line and a label.
crv = ChipsCurve()
crv.line.style = "noline"
crv.symbol.style = "square"
crv.symbol.size = 3.0
crv.symbol.fill = 0
add_curve("spectrum.fits[data][cols x,y]",crv)
crv = ChipsCurve()
crv.symbol.style = "none"
crv.line.color = "red"
crv.line.thickness = 2
add_curve("spectrum.fits[fit][cols x,y]",crv)
log_scale(XY_AXIS)
set_plot_xlabel("Energy (keV)")
set_plot_ylabel("Count s^{-1} keV^{-1}")
set_plot_title("Source spectrum")
set_xaxis(["offset.perpendicular",35])
set_plot(["leftmargin",0.25])
set_yaxis(["offset.perpendicular",45])
add_line(0.6,3.0e-4,0.9,3.0e-4,["color","red","thickness",2])
add_label(1.0,3.0e-4,"Model",["color","red","valign",0.5])
Two curves are created - in this case from different blocks in the same data file; the first, from the data block, is displayed as open squares and the second curve, which is from the fit block, is drawn as a solid red line. Labels are added to the plot axes and title (these labels can include a subset of LaTeX commands), and the plot re-arranged to make all the labels fit into the display area. Finally, a line and label are added to the plot to label the second curve. In this example a single segment line is used, so only the start and end locations are given in the add_line call. The vertical alignment of the label is adjusted so that it is centered on the line The info and info_current can be used to find out what objects have been created and which are current:
chips> print info()
Window [win1]
Frame [frm1]
Plot [plot1] (0.25,0.20) .. (0.90,0.90)
Border bottom [bx1] top [bx2] left [by1] right [by2]
X Axis [ax1]
Y Axis [ay1]
Curve [crv1]
Curve [crv2]
Line [line1]
Label [lbl1]
chips> print info_current()
Window [win1]
Frame [frm1]
Plot [plot1]
X Axis [ax1]
Y Axis [ay1]
Curve [crv2]
Line [line1]
Label [lbl1]
Coord Sys [Data]
Coord Sys ID [plot1_ax1ay1]
Two curves in the same plot, one with error barsHere we plot the same data as used in the Two curves in the same plot example, but this time we create a rectangular plot and also display error bars on the first curve.
add_window(6.0,3.0,"inches")
crv = ChipsCurve()
crv.line.style = "noline"
crv.symbol.style = "square"
crv.symbol.size = 3.0
crv.symbol.fill = 0
add_curve("spectrum.fits[data][cols x,y,dylo,dyhi]",crv)
crv = ChipsCurve()
crv.symbol.style = "none"
crv.line.color = "red"
crv.line.thickness = 2
add_curve("spectrum.fits[fit][cols x,y]",crv)
log_scale(XY_AXIS)
limits(X_AXIS,0.5,10.0)
set_plot_xlabel("Energy (keV)")
set_plot_ylabel("Count s^{-1} keV^{-1}")
set_xaxis(["offset.perpendicular",35])
set_plot(["leftmargin",0.15])
set_yaxis(["offset.perpendicular",45])
As with other ChIPS objects, windows will be created automatically for you if needed (e.g. by a call to add_curve). In this example we explicitly create the window using add_window so that we can control the window size. We pick a rectangle 6 inches wide and 3 inches high; these sizes refer to the postscript/PDF output size and will only be approximate for the on screen display; the screen size depends on the dot-pitch of your monitor and can be set using the scalewidth and scaleheight window settings when the window is created. Since a window exists, the first add_curve call will use it instead of creating a new one. Since the Data Model filter selects four columns from the file - namely x, y, dylo, and dyhi - the curve is plotted with asymmetric Y error bars. Although in this case the window size was explicitly set, print_window can be made to create postscript and PDF plots of a different size by using some or all of the pagesize, pagewidth, pageheight, fittopage, and keepaspect export options. |
![]() |
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. |