0
$\begingroup$

Suppose, I have a table with five columns where first four columns represent some variable parameters and fifth column represents value of function at those parameters. I want to have a contour plot for every possible combination of these four parameters. For example- First Using first and second column then first and third and so on. One way to do this is to plot every possible combination of these parameters and write ListContourPlot command for every combination. Is there any minimal way to plot contours for every possible combination? I have tried-

For[i = 1, i <= 10, i++,
d1 = RandomReal[{100, 1000}];
d2 = RandomReal[{100, 1000}];
d3 = RandomReal[{100, 1000}];
d4 = RandomReal[{100, 1000}];
d5 = d1 + d2 + d3 + d4 ;
list[i] = {d1, d2, d3, d4, d5};
]
list1 = Table[list[i], {i, 1, 10}];
list2 = list1[[All, {1, 2, 5}]];
list3 = list1[[All, {1, 3, 5}]];
list4 = list1[[All, {1, 4, 5}]];
ListContourPlot[list2]
ListContourPlot[list3]
ListContourPlot[list4]
$\endgroup$
  • $\begingroup$ Can you present a minimal example? What have you tried? $\endgroup$ – Mauricio Fernández Apr 6 '17 at 13:31
  • $\begingroup$ @MauricioLobos I have edited the question. $\endgroup$ – solphy101 Apr 6 '17 at 13:46
  • 2
    $\begingroup$ Try this: Table[ListContourPlot[list[[All, Append[xy, 5]]]], {xy, Subsets[Range[4], {2}]}] $\endgroup$ – J. M.'s discontentment Apr 6 '17 at 13:54
  • $\begingroup$ @J.M. How can I give specific frame labels for each plot? $\endgroup$ – solphy101 Apr 6 '17 at 14:32
  • $\begingroup$ Look up PlotLabel. $\endgroup$ – J. M.'s discontentment Apr 6 '17 at 14:39
2
$\begingroup$

Here is how to get all possible pairs of contour plots.

First, generate data (avoiding the notorious For function):

n = 100;  (* Number of samples *)
k = 4; (* Number of predictor variables *)
(* Generate data *)
data = RandomReal[{100, 1000}, {n, k + 1}];
(* (k+1)-th variable as a function of the first k variables *)
data[[All, k + 1]] = Sum[data[[All, i]], {i, k}];

Now produce all possible pairwise plots:

pairs = Select[Tuples[Range[1, k], 2], #[[1]] < #[[2]] &];
Table[ListContourPlot[data[[All, Flatten[{pairs[[i]], k + 1}]]]], {i, Length[pairs]}]

All possible pairwise plots

| improve this answer | |
$\endgroup$
  • $\begingroup$ Consider using Subsets[] instead of Tuples[]. $\endgroup$ – J. M.'s discontentment Apr 6 '17 at 15:03
  • 2
    $\begingroup$ Thanks @J.M. (This is one of the reasons I attempt to answer these questions. You folks help me (and everybody else) learn to be more efficient and expose us to the zillions of commands I don't know.) $\endgroup$ – JimB Apr 6 '17 at 15:05
1
$\begingroup$
SeedRandom[1]
For[i = 1, i <= 10, i++,
 d1 = RandomReal[{100, 1000}];
 d2 = RandomReal[{100, 1000}];
 d3 = RandomReal[{100, 1000}];
 d4 = RandomReal[{100, 1000}];
 d5 = d1 + d2 + d3 + d4;
 list[i] = {d1, d2, d3, d4, d5};]
list1 = Table[list[i], {i, 1, 10}];

Note that this can be coded more simply as

SeedRandom[1]
list2 = Flatten[{#, Total[#]}] & /@
   RandomReal[{100, 1000}, {10, 4}];

Verifying the equivalence,

list1 === list2

(*  True  *)

EDIT Added labels

labels = {"a", "b", "c", "d", "Total"};

(ListContourPlot[
      list1[[All, {#[[1]], #[[2]], 5}]],
      FrameLabel -> (Style[#, 14, Bold] & /@labels[[#]]),
      PlotLabel -> Style["ContourPlot of " <> Last[labels], 14, Bold]] & /@
    Subsets[Range[4], {2}]) //
  Partition[#, 2] & //
 Grid[#, Spacings -> {2, 2}] &

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ How can I give specific frame labels to each plot? $\endgroup$ – solphy101 Apr 6 '17 at 14:37
  • $\begingroup$ Total no. of plots should be six? $\endgroup$ – solphy101 Apr 6 '17 at 15:52
  • $\begingroup$ @solphy - I merely produced what was shown in your code. $\endgroup$ – Bob Hanlon Apr 6 '17 at 21:30
  • $\begingroup$ Is it possible to label elements of the list and use those labels as FrameLabel for each individual plot? $\endgroup$ – solphy101 Apr 7 '17 at 5:50
  • 1
    $\begingroup$ @solphy - spend some time formulating your questions so that they are completely described and do not need repeated modifications. $\endgroup$ – Bob Hanlon Apr 7 '17 at 6:21

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.