2
$\begingroup$

Let's say that I have the following Dataset:

ds = Dataset[
   AssociationThread[{"A", "B"}, #] & /@ {{Range[10], 
      Sin[#] & /@ Range[10]}, {Range[10], 
      Cos[#] & /@ Range[10]}, {Range[10], Tan[#] & /@ Range[10]}}];

In column B, you have in each row respectively: Sin, Cos and Tan of the values that are in the same row of A.

How can do a ListPlot of those three rows in the most convenient way ?

$\endgroup$
4
  • 2
    $\begingroup$ That's... a really weird format. Do you actually get a Dataset[] shaped like this in your actual problem? $\endgroup$ Apr 10, 2018 at 14:30
  • 1
    $\begingroup$ Can you consider re-formatting, eg to this? Range[10] // Map[<|"A" -> #, "B" -> Cos[#], "C" -> Sin[#], "D" -> Tan[#]|> &] // Dataset . Then you can plot pairs like: ds2[All, {"A", "B"} /* Values] // ListPlot $\endgroup$ Apr 10, 2018 at 14:36
  • $\begingroup$ @J.M. I agree. The reason: I am acquiring experimental data of a reflection spectrum of different samples. Each sample is specified by a set of parameters, like size, thickness etc. -> one number for each parameter. For each of those samples, I record the "wavelength" and the "reflection" -> those two are lists, for the wavelength from 400nm to 800nm and for the reflection you have a value between 0 and 1 depending on your wavelength. So basically I have a table where in the first columns there is only one number, and in the last two, there are lists. $\endgroup$
    – james
    Apr 10, 2018 at 15:19
  • $\begingroup$ @J.M. I figured a way how to change the dataset structure. $\endgroup$
    – james
    Apr 10, 2018 at 15:29

1 Answer 1

2
$\begingroup$

Assuming that each row represents a list with x values (key A) and y values (key B), I would do something like this to get all data in 1 plot:

ListPlot[Transpose[{#A, #B}] & /@ ds]
$\endgroup$
1
  • $\begingroup$ Great ! Thanks a lot ! $\endgroup$
    – james
    Apr 10, 2018 at 15:30

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.