4
$\begingroup$

Suppose I have these two lists:

data1 = {{2002, 120.022}, {2003, 153.253}, {2004, 112.327}, {2005,148.647}, {2006, 95.8467}, {2007, 119.702}, {2008, 120.022}, {2009,104.635}, {2010, 135.413}, {2011, 263.054}, {2012, 152.658}, {2013,271.251}, {2014, 133.85}}
data2 = {{2002, 0.33693}, {2003, 0.504899}, {2004, 0.213245}, {2005,0.292028}, {2006,0.184824}, {2007, 0.207512}, {2008, 0.33693}, {2009,0.116137}, {2010, 0.318169}, {2011, 0.23199}, {2012, 0.207042}, {2013,0.407042}, {2014, 0.316603}}

I want to plot all the second elements of data1 with those of data2, but then have it ordered according to the year. I can do this as follows

ListPlot[Transpose[{data1[[All, 2]], data2[[All, 2]]}]]

However what happens here is that the data points are ordered according to the x-elements in ascending order:

enter image description here

I would like the data points on the list plot to be ordered according to the year from which they arrived in ascending order - from left to right. I guess something like:

{{2002,{120.022,0.33693},{{2003,{153.253,0.504899}},...,{2014,{133.850.316603}}}

I just don't know how to get Mathematica to list plot it in that order from 2002 - 2014.

$\endgroup$
3
$\begingroup$
data1 = {{2002, 120.022}, {2003, 153.253}, {2004, 112.327}, {2005, 
    148.647}, {2006, 95.8467}, {2007, 119.702}, {2008, 120.022}, {2009, 
    104.635}, {2010, 135.413}, {2011, 263.054}, {2012, 152.658}, {2013, 
    271.251}, {2014, 133.85}};
data2 = {{2002, 0.33693}, {2003, 0.504899}, {2004, 0.213245}, {2005, 
    0.292028}, {2006, 0.184824}, {2007, 0.207512}, {2008, 0.33693}, {2009, 
    0.116137}, {2010, 0.318169}, {2011, 0.23199}, {2012, 0.207042}, {2013, 
    0.407042}, {2014, 0.316603}};

You want to plot data with three dimensions. There are many ways to do this.

data = Transpose[{data1, data2}] /.
   {{x_, y1_}, {x_, y2_}} :> {x, y1, y2};

DateListPlot[
 Labeled[{{#[[1]]}, #[[2]]}, #[[3]]] & /@
  data, PlotRange -> All]

enter image description here

DateListPlot[
 Labeled[{{#[[1]]}, #[[3]]}, #[[2]]] & /@
  data]

enter image description here

BubbleChart[data]

enter image description here

BubbleChart[{#[[1]], #[[3]], #[[2]]} & /@ data]

enter image description here

ListPointPlot3D[data]

enter image description here

$\endgroup$
  • $\begingroup$ Of course, I guess since I was so tunnel visioned on getting a 2D plot, i didn't think of the extensions of using 3D data. Thanks $\endgroup$ – Luca Pontiggia Apr 18 '17 at 12:43

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.