I have the following data:

  setA = {
  {875, 0.399483}, 
  {880, 0.391583}, 
  {885, 0.383609}};
  setB = {
  {645, 0.690354}, 
  {650, 0.685416}, 
  {655, 0.680413}};

I'm trying to plot the data from both sets on the same plot. I can do the following:

var[set_,col_] := set[[All, col]];

setAx = var[setA,1]; setAy = var[setA,2]; 
setBx = var[setB,1]; setBy = var[setB,2];

then plot:

valplot[var1_, var2_, opts_] := 
ListPlot[Transpose[{var1, var2}], PlotRange -> All, 
PlotStyle -> {Red}, Joined -> False, opts]

setsAandBPlots = GraphicsGrid[{
                  {setAyPlot = valplot[setAx, setAy, AxesLabel -> {"variable x", "variable y"}]}

                    (* ,etc... *)
                    }, ImageSize -> 300]

This is pretty clunky, I know (i'm very new to programming - and i'm starting with mathematica...).

I want to make a series of these plots comparing different sets (and the actual datasets i'm using are much larger than these - many more rows and columns)

I would like to be able plot multiple subsets (e.g. "(setAx and setbx) versus (setAy and SetBy)", etc...) on the same plots (defined by different colored markers) using something like "Show". There must be a neat(er) way to do it using, say, "Position" and "Intersection" to pick the individual values for plotting.

I guess I'm asking if any one can help me find a more general/programatic way to populate the lists "setAx, setAy,setBx, etc..." without having to write them out long-hand?



Sorry I oversimplified my data. It looks more like this:

setA = {{8.0, 830, 0.466626, 1.720689,0.200740, 0.018637, 0.009023, 0.029482, 0.091949, 0.074304, 0, 0}, 
        {8.0, 835, 0.459588, 1.742870, 0.202380, 0.019201, 0.010261, 0.032965, 0.093269, 0.074717, 0, 0}}; 
setB = {{8.0, 845, 0.445114, 1.787952, 0.205660, 0.020367, 0.013240, 0.041201, 0.095895, 0.075504, 0, 0}, 
        {8.0, 850, 0.437659, 1.810861, 0.207301, 0.020968, 0.015022, 0.046038, 0.097197, 0.075877, 0, 0}};

so, the data is essentially of the form {{A1x, A1y, A1z,…},{A2x,…}}; {{B1x, B1y, B1z,…},{B2x,…}};.

I'd like to be able to plot various combinations with axes: x vs. z, y vs. z etc. ListPlot alone won't help me do this... hence the use of new lists of the form Transpose[{Ax, Az}] etc..

  • $\begingroup$ Are you sets of the form {x, y1, y2, ...} ? $\endgroup$ Commented Nov 19, 2012 at 11:22
  • 2
    $\begingroup$ How does the approach ListPlot[{setA, setB}] work for you ? $\endgroup$ Commented Nov 19, 2012 at 12:04
  • $\begingroup$ ListPlot supports plotting of multiple lists, as image_doctor points out, see reference.wolfram.com/mathematica/ref/ListPlot.html, so plotting of your reference data works fine. $\endgroup$
    – FredrikD
    Commented Nov 19, 2012 at 12:56
  • $\begingroup$ b.gatessucks, essentially yes. Sorry I over simplified my data. $\endgroup$
    – geordie
    Commented Nov 19, 2012 at 20:03
  • $\begingroup$ I think I understand listplot. Please see below for an example of what my actual datasets look like. Nasser, Union seems to combine the lists so I lose the independence of the sets... $\endgroup$
    – geordie
    Commented Nov 19, 2012 at 20:32

2 Answers 2


for x vs y plot:




is a list of point coordinates with respect to what you specify by {firstAxe,secondAxe}.

X axe stands for 1, Y for 2 and Z for 3.

  • $\begingroup$ Thanks! this is not quite the way I was thinking of solving the problem but it works fairly nicely. however i needed to change your code to: ListPlot[{setA[[All,{1,2}]],setB[[All,{1,2}]]}] (i.e. add curly brackets) in order to compile. $\endgroup$
    – geordie
    Commented Nov 19, 2012 at 23:54

The straightforward approach to answering the main part of your question, i.e. "..plot multiple subsets..using something like Show" is to use ListPlot on a list of data, see the manual on ListPlot

setA = {{875, 0.399483}, {880, 0.391583}, {885, 0.383609}};
setB = {{645, 0.690354}, {650, 0.685416}, {655, 0.680413}};

ListPlot[{setA, setB}]

which gives you a diagram like this: enter image description here

ListPlot automatically gives the data sets different colors and you can use other functions such as Tooltip, StatusArea and Annotation to add interactive labeling.

To automatically populate the lists from a source outside of Mathematica, I can recommend this post about getting data from Excel.

  • $\begingroup$ @FerdrikD, thanks for your answer, not quite what i'm after (see edit). Thanks for the link to the excel import question (it could come in handy). The data in this case do not come from excel. I tend to use textwrangler to format data for input. $\endgroup$
    – geordie
    Commented Nov 19, 2012 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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