Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.7K Views
|
5 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Produce a ListPlot with Dataset

Posted 4 years ago

Suppose I have the following Dataset: enter image description here

I want to use ListPlot to produce a plot of v (voltage) vs. t (time). Seems quite simple and straightforward, but I didn't find an answer on the net. I was thinking about doing

ListPlot[Thread[{mydata[All, "t"], mydata[All, "v"]}]]

but mydata[All, "t"] gives an error:

Failure[Dataset,Association["MessageTemplate" :> MessageName[Dataset, "partnotapplicable"],"MessageParameters" -> Association["Type" -> TypeSystem`Vector[TypeSystem`AnyType, 2], "Part" -> "t","Symbol" -> Part]]]

I wouldn't be surprised to learn that there is a short way to do that, without the use of Thread.

POSTED BY: Ehud Behar
5 Replies
Posted 4 years ago

@ Neil Singer

and

@ Rohit Namjoshi,

Thanks very much indeed. Both your suggestions work.

POSTED BY: Ehud Behar

In addition to Rohit's suggestion, SemanticImport will import the data as a dataset:

ds = SemanticImport["~/Downloads/sample_file.csv"]
ds[ListPlot, {"t", "v"}]
POSTED BY: Neil Singer
Posted 4 years ago

Hi Ehud,

If the csv has a header row with column names then use this to Import as a Dataset.

ds = Import["~/Downloads/sample_file.csv", "Dataset", HeaderLines -> 1]

Notice that in this case the Dataset is rendered differently, the first row is a darker gray.

ds[ListPlot, {"t", "v"}]

Compare

InputForm@dataset
InputForm@ds
POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hmmm... Thanks very much for you reply!

But, something isn't working for me.

I keep getting a "Failure" error - the one I wrote in the original post. Do you think it has something to do with the way I generate the csv file?

I am using Google Spreadsheet for this task, and the csv file is finely imported to the notebook.

I am also working on Mathematica 12.1 on Windows 7 64bit.

I wonder what I am missing here.

My notebook reads:

dataset = Import["filename.csv", "Dataset"]
dataset[ListPlot, {"t", "v"}]

I attached the sample .csv file to this post, if that could help.

Attachments:
POSTED BY: Ehud Behar

Ehud,

Do either

dataset[ListPlot, {"t", "v"}]

dataset[ListPlot, {#t, #v} &]

To get your plot.

Datasets are not lists but you can turn them into lists or some other format with the second example above (applying a function to the data). Look at the planet example or the titanic example in the help on Dataset.

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard