3
$\begingroup$

Suppose I have tabular data usual for numeric packages:

T = Table[{x, Sin[x], Cos[x]}, {x, 0, 1, 0.1}];
T // TableForm

Now I want to plot T. I want to plot it discrete as two point plots against single x. How can I do that?

I can't catch how to use some of ListPlots here.

$\endgroup$
  • 2
    $\begingroup$ ListLinePlot[Transpose[Rest /@ T], DataRange -> T[[ {1, -1}, 1]]] ? $\endgroup$ – Kuba Oct 17 '14 at 10:05
  • $\begingroup$ Or ListPlot[..., Filling -> Bottom] if you want the DiscretePlot style $\endgroup$ – Öskå Oct 17 '14 at 10:07
  • $\begingroup$ @Kuba isb't there some simpler function ready made? $\endgroup$ – Suzan Cioc Oct 17 '14 at 11:00
  • 1
    $\begingroup$ @SuzanCioc One can not expect that there will be sparate function for each data structure you can imagine :) $\endgroup$ – Kuba Oct 17 '14 at 12:50
  • 1
    $\begingroup$ This structure was imagined not by me, but by numerous creators of numeric packages, like Excel, Matlab, Statistica etc. $\endgroup$ – Suzan Cioc Oct 17 '14 at 14:07
4
$\begingroup$
ListPlot[{T[[All, {1, 2}]], T[[All, {1, 3}]]}]

or

ListPlot[T[[All, {1, #}]] & /@ {2, 3}]

plot screenshot

$\endgroup$
5
$\begingroup$

Here are some ways:

pd = Map[Function[x, Thread[{#1, x}]], {##2}] & @@ Transpose[tab];
ListPlot[pd]

or

ListPlot[Transpose /@ ({{#1, #2}, {#1, #3}} & @@ Transpose[tab])]

As comments note you can also use:

DiscretePlot[{Sin[x], Cos[x]}, {x, 0, 1, 0.1}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.