Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to specify x-axis in List when using ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg127899] Re: How to specify x-axis in List when using ListPlot
  • From: Paul E McHale <paulmchale at me.com>
  • Date: Fri, 31 Aug 2012 03:56:25 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

If you are not familiar with some of the commands, it is easiest to delete the semicolons at the end of the lines to understand what each line does.  At least this is what I do "step" through code.

This should work for any size list as long as x value is first value on each line.


(* begin code *)
mData={{1,8,9,1},{2,2,8,1},{3,8,9,2},{4,3,7.5,2},{5,3,7.5,1}};

(*Pull out each first element into own list*)
xValues=Transpose[mData][[1]];

(*Generate separate lists for the y values*)
yValues=Drop[Transpose[mData],1];

(*Combine (Riffle[]) xValues with each individual list of yValues *)
tobeplotted=Map[Riffle[xValues,#]&,yValues];

(*form (Partition[]) new list made up of two elements each*)
tobeplotted=Map[Partition[#,2]&,tobeplotted];

(* Previous two lines can be combined *)
(* tobeplotted=Map[Partition[Riffle[xValues,#],2]&,yValues]; *)

(*Plot all lists together on one plot*)
ListPlot[tobeplotted,PlotStyle->{Red,Blue,Green},PlotMarkers->{Automatic,10}]



  • Prev by Date: Re: reduction/simplification of hypergeometric-function-related
  • Next by Date: Re: Extracting Parameter Values from NonlinearModelFit
  • Previous by thread: Re: How to specify x-axis in List when using ListPlot
  • Next by thread: Luke's list of mathematica questions