Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plotting data in mathematica

  1. Feb 5, 2008 #1
    (not for homework, just for fun)

    I'm doing research with my professor, and as an 'easy project' (har har) she gave me the task to replicate the CFA Redshift Survey in a polar graph plot. So with some clever googling I found the .dat file that has the most recent info in it, and I'm fairly confident I know which numbers to plot vs what and how to bound it and all, but the whole process of actually importing the data and plotting the points is a pain. Anyone have any ideas?
     
  2. jcsd
  3. Feb 5, 2008 #2

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    Suppose you put the data into Excel.

    In Math'ca type

    data = Import[at which point go to Insert menu, then select File Path, then (in the dialog box) double-click on the Excel data file

    then type ] to close the Import bracket.

    The input line will look like:
    data = Import["C:\\My Documents\\Excel file.xls"]

    Put the cursor anywhere on the line and hit Shift+Enter.

    Math'ca will take a second or two to read the data.

    You will have created a Math'ca data table named data. For example, typing

    data[[1]]

    then shift+entering will print the first row of the data. (If that doesn't work, try data[[1,1]].) Likewise, data[[1,4]] (or data[[1,1,4]]) will print the 4th column on the first row.
     
  4. Feb 5, 2008 #3
    Thank you x a billion, enuma, but now that I have my data in it, how would one plot this wackyness as a function of radial distance vs angle? eg, plotting data points in polar coordinates?
     
  5. Feb 5, 2008 #4

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    If you go to Math'ca help (F1 on the keyboard) then type "polar" as the search term, you'll see (among others):

    ListPolarPlot[{r1, r2, ...}]
    plots points equally spaced in angle at radii ri.

    ListPolarPlot[{list1, list2, ...}]
    plots several lists of values.
     
  6. Feb 5, 2008 #5
    I guess I misspoke (mistyped?) when I said 'polar'. Pretty much I have to replicate this. I have the data, I just don't know how to fumble with the plotting tools, since excel doesn't fit the bill.

    Does the ListPolarPlot function allow me to plot like in the link above?
     
  7. Feb 5, 2008 #6

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    Carefully look at the examples under ListPolarPlot help.

    ListPolarPlot[Table[Sqrt[n],{n,100}]] will produce a conch (spiral) pattern. Note that
    Table[Sqrt[n],{n,100}] = {1., 1.41421, 1.73205, 2., 2.23607, 2.44949, 2.64575, 2.82843, 3., 3.16228, 3.31662, 3.4641, 3.60555, 3.74166, 3.87298, 4., 4.12311, ..., 10}. If your data look like these numbers, ListPolarPlot will produce this pattern.

    ListPolarPlot[Table[{n,Log[n]},{n,500}]] will produce a starfish (?) pattern. Note Table[{n,Log[n]},{n,500}] = {{1, 0.}, {2, 0.693147}, {3, 1.09861}, {4, 1.38629}, {5, 1.60944}, ..., {500, 6.21461}}. If your data look like these pairs of numbers, then ListPolarPlot will produce this pattern.
     

    Attached Files:

    Last edited: Feb 5, 2008
  8. Feb 6, 2008 #7

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    Looking at the sky plot you posted, I suspect that your data are in sky coordinates (altitude, azimuth). If so, you need to transform your data points into an (angle, radius) representation before you plot them using ListPolarPlot.

    In Math'ca help, the input line that produces the spiral pattern consists of a list of numbers. Math'ca interprets each of these numbers as a radius (and plots them with uniformly spaced angles).

    The input line that produces the starfish pattern consists of a list of number pairs. Math'ca interprets the first element of each pair as an angle and the second element of the pair as a radius.

    You may wish to post under the PF Astronomy forum for further help on this conversion.
     
    Last edited: Feb 6, 2008
  9. Feb 6, 2008 #8
    I tried doing what you suggested, but I keep getting this. I don't know where the periods after the x values keep coming from, since they're not in my excel spreadsheet, if that's the error.
     
  10. Feb 7, 2008 #9

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    I see the problem, you have too many {}'s wrapped around your list.

    When defining data, you don't need to wrap {} around Import[].

    Try removing those and then see if it works.

    The periods are harmless; they mean "floating point number" (as opposed to "integer" or "fraction"). It's a programming convention.
     
    Last edited: Feb 7, 2008
  11. Feb 7, 2008 #10
    fah! it keeps giving me the same output as before, even without the {}s. Thanks for your patience, by the way.
     
  12. Feb 7, 2008 #11

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    Try inputting data and ListPolarPlot as separate input statements.

    FYI, when I copy & paste your data points I can generate a real picture (see attached).
     

    Attached Files:

  13. Feb 7, 2008 #12
    I googled the ListPolarPlot function and it comes under a "new in 6" page. I have mathematica 5.1. I'm assuming its just some package thing I'm missing then...or...at least I hope it is!
     
  14. Feb 8, 2008 #13

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    That would definitely explain it!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Plotting data in mathematica
Loading...