Message Boards Message Boards


DateListPlot Databin fails to scale

Posted 6 years ago
8 Replies
0 Total Likes

I'm just getting started with DataDrop. I've got a Particle Photon logging sensor data to a Databin, which was super easy and great. Now I've got some data to work with. I'm using the Dev Platform notebook, I can see the data bin with Databins[], I can check there is data present with TimeSeries[Databin[""]], which tells me that I've got 700 data points from 03 Oct to 04 Oct.
But when I use DateListPlot on that same databin, i get a plot that is scaled from 0.0 to 1.0 on the Y axis and 00:00:00 to 00:00:01 on the X axis. My data values are between 70 and 80. I can't find any reference on how to set proper scaling on this function. Then when I use Dataset on that bin my data looks like this:

enter image description here

Any ideas on how I can get this data set time stamp in the proper format? I don't send any time info when the device sends the sensor data, I think that is handled automagically by Wolfram.

8 Replies

DateListPlot should just plot your data. If it shows your values being betwen 0 and 1 then it is probably because the data you are giving it is between 0 and 1.

Can you give a small snippet of your data? Or something to help us reproduce the problem?

One thing you can do is to run Normal on the dataset. This will turn it into a list, which is easier to copy.

Posted 6 years ago

Can you access the data directly? It's in a public data bin. I'm accessing with:


Let's look at the first set and the first value.


To see what the actual value is, use InputForm. This will show you exactly what the first element is.

{{2015, 10, 3, 21, 29, 30.087313175201416}, "74.20"}

When you make a Databin, it will assume everything is a string unless you specify some kind of type, like "Number". Here is how work aroudn the current problem:

(* get the data as a simple list of values *)
data = Normal[TimeSeries[Databin["7j5P9Pz2"]]["temp1"]]

(* turn the temps from strings into numbers *)
data = data /. {date_, temp_} :> {date, ToExpression@temp}

(* alternatively you could turn the temps from strings into numbers this way *)
data = MapAt[ToExpression, data, {All, 2}]

DateListPlot will now work with the variable "data".

I have a similar scenario. I'm just trying to get a simple visualization of logged temperatures. I use

data = Normal[TimeSeries[Databin["91DkM20b"]]["temp"]]

Then I see a list of dates/temp values like you would expect ( pretty sure they are numbers not strings) :

{{December 16, 2015 2:46 pmGMT-8.,32.0625},{December 16, 2015 2:46 pmGMT-8.,32.125},{...etc...

But when I use DateListPlot on data, I still get a plot that is scaled from 0.0 to 1.0 on the Y axis and 00:00:00 to 00:00:01 on the X axis, as originally described by this question asker. Any ideas?

Can you take on the pairs of data and then run InputForm on it?

What does your data look like?

Ah, I guess that helps explain it I get :

{DateObject[{2015, 12, 16}, TimeObject[{14, 46, 56.76739978790283}, TimeZone -> -8.], TimeZone -> -8.], "32.0625"}

Mathematica does a lot of formatting to make code more readable, but it's sometimes confusing at first. You can think of InputForm as a function that shows you what your code "actually" looks like.

Databin by default will make strings. You have to ask it to interpret it's input as anything else.

To fix your code, let's make a function that takes a pair of values and runs "ToExpression" on the last part. ToExpression in this case will take a string of a number and turn it into a number:

fixPair[{a_, b_}] := {a, ToExpression[b]}

We can then Map this function onto your data:

fixedData = Map[fixPair, data]

Hmm, I'm getting a $Failed output. With a data output saying {"mydata"} is protected.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract