0

I have imported an array into my IPython notebook using the following method:

SDSS_local_AGN = np.fromfile('/Users/iMacHome/Downloads/SDSS_local_AGN_Spectra.dat', dtype=float)

The array is of the form:

 SPECOBJID_1         RA          DEC           SUBCLASS ...
 299528159882143744  146.29988   -0.12001413   AGN      ...
 299532283050747904  146.32957   -0.30622363   AGN      ...

Essentially each column has a header, and I now need to plot certain values.

As an example, I want to plot RA against DEC...how would I go about doing this?

Perhaps:

axScatter.plot(SDSS_local_AGN[RA], SDSS_local_AGN[DEC])
1
  • np.fromfile(file, dtype=float) (using the default sep='') reads a binary file of floating point values. How can your array have "columns" containing integers (SPECOBJID_1) or strings (SUBCLASS)? Commented Feb 2, 2015 at 22:15

1 Answer 1

1

Answer is mistaken, see comments

If you want to access them via name, you should use pandas instead of numpy. In numpy, you need to lookup by index:

plt.scatter(SDSS_local_AGN[1], SDSS_local_AGN[2])

But in pandas, it would be as simple as:

df = read_csv('myfile')
df.plot(kind='scatter', x='RA', y='DEC')

http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html#scatter-plot

SDSS_local_AGN['RA'] is a valid operation in pandas, but not in numpy.

PS, since you are working in a Notebook, pandas DataFrames will nicely render as HTML tables, making them much more readable.

Sign up to request clarification or add additional context in comments.

4 Comments

Correction: SDSS_local_AGN['RA'] is valid in numpy, if SDSS_local_AGN is a structured array (see docs.scipy.org/doc/numpy/user/basics.rec.html). If the file was a text file with the layout shown in the question, it could be read into a structured array with, for example, SDSS_local_AGN = np.genfromtxt('filename.dat', names=True). However, it is binary file, so neither np.genfromtxt nor pandas.read_csv will work.
I didn't realize this, sorry.
The question is confusing (to me, anyway). I don't see how the binary data read with np.fromfile(...) can have the "columns" shown in the question.
I'm wondering if OP used "genfromtxt" and posted "fromfile" instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.