Chandra X-Ray Observatory
Skip to the navigation links
Last modified: 14 December 2016

How do I plot a histogram from a file?

The make_figure and add_histogram commands can plot data from a file (in both FITS binary and ASCII formats). The numpy histogram() command can be used to create a histogram of a column of data for display with add_histogram.

  1. Two columns: A set of (xmid,y) points.

    make_figure("file.lis[cols x,y]","histogram")
    add_histogram("file.lis[cols x,y]")

    This will plot up columns x and y from the file file.lis, and use x as the middle of each bin.

  2. Two columns: A set of ([xlo,xhi],y) points.

    make_figure("file.fits[cols r,sur_bri]","histogram")
    add_histogram("file.fits[cols r,sur_bri]")

    If the first column selected - here r - is a vector column with two values per row, then these two values will be used as the low and high bounds of each bin. An example of this case is when dmextract has been used to create a radial profile; the R column contains the inner and outer edges of each annulus and so can be used to define the histogram bins.

  3. One column: A set of points to histogram.

    If you have a set of points which you want to "bin up" to create a histogram then you have to read them in and then use the histogram command from numpy to create the values for use with add_histogram. For example:

    cr = read_file("asol1.fits")
    ra = copy_colvals(cr, "ra")
    (counts, edges) = np.histogram(ra, bins=100)
    xlo = edges[:-1]
    xhi = edges[1:]
    add_histogram(xlo, xhi, counts)

    More help on histogram can be accessed at the ChIPS prompt by saying

    chips> help np.histogram

    or by visiting the NumPy web site (noting that CIAO 4.9 uses version 1.11.0 of NumPy).

Last modified: 14 December 2016
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.