Multiple 24-hour periods as separate plots in one chart | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Multiple 24-hour periods as separate plots in one chart
No permission to create posts
July 21, 2017
5:44 pm
Avatar
jbeale1
New Member
Members
Forum Posts: 3
Member Since:
July 21, 2017
sp_UserOfflineSmall Offline

I can plot 48 hours of data in one plot, for example I ask for

https://api.thingspeak.com/channels/304707/charts/1?width=900&height=600&timescale=10&days=2

and I get a plot like: https://photos.app.goo.gl/TUQnBL7kfxwzwfbl2

That's good. Now, is it possible to plot that same data using only 24 hours on the horizontal axis, and two separate traces for each day's data, so if for example today is a little warmer than yesterday, the second trace sits a little above the first one?

The point is to better compare day-over-day differences at each hour of the day.  If that is possible, how?  Thanks for any help!

July 24, 2017
4:26 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 210
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

MATLAB and ThingSpeak have many options for plotting.  Take a look at the documentation for thingSpeakPlotYY.  Also thingSpeakRead to see the options for reading dates.

Here is one possibility you can use in MATLAB visualization.

dataToday=thingSpeakRead(304707,'DateRange',[datetime('today')-caldays(1),datetime('today')],'OutputFormat','Timetable');

dataYesterday=thingSpeakRead(304707,'DateRange',[datetime('today')-caldays(2),datetime('today')-caldays(1)],'OutputFormat','Timetable');

thingSpeakPlotYY(1:height(dataToday),dataToday.G_Battery,1:height(dataYesterday),dataYesterday.G_Battery);

July 26, 2017
1:53 am
Avatar
jbeale1
New Member
Members
Forum Posts: 3
Member Since:
July 21, 2017
sp_UserOfflineSmall Offline

Thank you very much for that suggestion! That code works fine for two lines showing two days. Then I tried to extend to 3 lines for 3 days, and using all the same X and Y axes (instead of double-Y axis type) so I used the matlab "plot" command with three (X,Y) data pairs. It works fine without error for the G_Battery and Garage channel, but fails on the third channel "Shed" saying "Error using plot  Invalid second data argument   Error in Custom (no starter code) 3 (line 17)  plot(x1,y1,x2,y2,x3,y3);"

Here is the code I'm trying (the commented-out lines work OK)

d1=thingSpeakRead(304707,'DateRange',[datetime('today')-caldays(1),datetime('today')],'OutputFormat','Timetable');
d2=thingSpeakRead(304707,'DateRange',[datetime('today')-caldays(2),datetime('today')-caldays(1)],'OutputFormat','Timetable');
d3=thingSpeakRead(304707,'DateRange',[datetime('today')-caldays(3),datetime('today')-caldays(2)],'OutputFormat','Timetable');

% x1=1:height(d1); y1=d1.G_Battery;
% x2=1:height(d2); y2=d2.G_Battery;
% x3=1:height(d3); y3=d3.G_Battery;

% x1=1:height(d1); y1=d1.Garage;
% x2=1:height(d2); y2=d2.Garage;
% x3=1:height(d3); y3=d3.Garage;

x1=1:height(d1); y1=d1.Shed;
x2=1:height(d2); y2=d2.Shed;
x3=1:height(d3); y3=d3.Shed;

plot(x1,y1,x2,y2,x3,y3);

July 28, 2017
2:03 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 210
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

The field for shed has some text data in it, so thingspeak is providing those as character vectors.  The plot() function won't plot characters.  There may be a function that exists to remove those from a cell array.  You could also just remove the text values, or put a loop in to remove them with an element by element search.  Be careful to write the elements you keep back to a type of double - when you read character arrays, MATLAB chooses to male the variable a cell array

July 28, 2017
10:36 pm
Avatar
jbeale1
New Member
Members
Forum Posts: 3
Member Since:
July 21, 2017
sp_UserOfflineSmall Offline

Ah, thank you, I didn't realize that since the default graph plot still worked for the Shed channel. Maybe it is a stray CR-LF at the end of line.  I changed the source Python code to convert incoming data string to float and then print that back into a string to add to the "GET https://..." line, hopefully that will work, thanks again!

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

celinabw2, FitoSprayscroma, LunnonGor, lancevl16, bernicenk60, veronicadq18

Administrators: Hans: 387, lee: 457