Solved

How to use ListLinePlot function with some data in a List in Mathematica 6?

Posted on 2008-11-18
336 Views
Hi,

I am a beginner of Mathematica. Now I have a question on drawing a diagram with some data in a List.

I have a 2-D List like this:
animal = { {Dog, 1}, {Cat, 2}, {Rabbit, 3}, ... }

How can I draw a line (ListLinePlot) with numbers in the List above only? In other words, I wish to draw a line with data 1, 2, 3, ... the names of animal can be ignored.

Thanks in advance for any help.

0
Question by:oscar_1470

LVL 6

Expert Comment

ListPlot - draws lines
animal[i][2] - will access numbers in your array (actually i-th element)

Combine those to get what you need. I dont have Mathematica here so I can not write a code, but if you dont succeed alone with this help I'll do it later :D
0

LVL 6

Expert Comment

I have not seen logical problem you have: point is defined with two variables x and y coordinate and you only have one ???
0

Author Comment

I have only data for y variable. The x axis just uses the natural number.
0

LVL 6

Expert Comment

What do you mean "natural number"? Please explain. Could you give an example?
0

Author Comment

Natural number means {1, 2, 3, 4, ...}

Given animal = { {Dog, 10}, {Cat, 20}, {Rabbit, 30}, ... }, the result diagram should be a line passing through {x, y} = {1, 10}, {2, 20}, {3, 30}, ...
0

LVL 6

Expert Comment

Sorry for not answering when I promised :( Here is the code:

``````animal = { {Dog, 1}, {Cat, 2}, {Rabbit, 3} }

myArray = {}

For[i=1, i<=Length[animal],i++,

AppendTo[myArray, {i, animal[[j,2]]}

]

ListPlot[myArray, PlotJoined->True]

(* or draw only points like this *)

ListPlot[myArray, PlotStyle->PointSize[0.05]

``````
0

LVL 6

Accepted Solution

Sorry, there is one bracket missing in code. Here is corrected version:

``````animal = { {Dog, 1}, {Cat, 2}, {Rabbit, 3} }

myArray = {}

For[i=1, i<=Length[animal], i++,

AppendTo[myArray, {i, animal[[j,2]]}];

]

ListPlot[myArray, PlotJoined->True]
``````
0

Author Closing Comment

0

Featured Post

A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …