3
$\begingroup$

Consider the following dataset:

keys = {"a", "b", "c", "d"};
vals = Partition[Range[20], 5]
ds = Dataset[AssociationThread[keys, #] & /@ Transpose@vals]

enter image description here

In order to plot the first two columns (a being x and b being y) we do:

ListPlot[{ds[All, {"a", "b"}]}]

enter image description here

But if we want to add the last two columns as shown below, we get an error.

ListPlot[{ds[All, {"a", "b"}], ds[All, {"c", "d"}]}]

How can I plot the first two columns and the last two columns on the same ListPlot?

enter image description here

(The above plot was obtain using ListPlot[{list1, list2}])

$\endgroup$

3 Answers 3

4
$\begingroup$

The following seems to work:

ds[ListPlot @* Thread @* Values, {{"a", "b"}, {"c", "d"}}]

enter image description here

Another variation:

ds[ListPlot @* Values @* Transpose, {{"a", "b"}, {"c", "d"}}]
$\endgroup$
3
$\begingroup$
ds[ListPlot @* Transpose, {{#a, #b}, {#c, #d}}&]

enter image description here

Slightly shorter variant:

ds[ListPlot[#] &, {{#a, #b}, {#c, #d}} &]

enter image description here

$\endgroup$
1
$\begingroup$

A dirty get around this is to convert Mathematica datasets to lists and plot it:

ListPlot[{Normal@Values@ds[All, {"a", "b"}], 
  Normal@Values@ds[All, {"c", "d"}]}]

enter image description here

$\endgroup$

Your Answer

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

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