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

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
Multiple 24-hour periods as separate plots in one chart
Avatar
jbeale1
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
1
July 21, 2017 - 5:44 pm
sp_Permalink sp_Print sp_EditHistory

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!

Avatar
cstapels

Gold
Forum Posts: 126
sp_UserOfflineSmall Offline
2
July 24, 2017 - 4:26 pm
sp_Permalink sp_Print

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);

Avatar
jbeale1
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
3
July 26, 2017 - 1:53 am
sp_Permalink sp_Print sp_EditHistory

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);

Avatar
cstapels

Gold
Forum Posts: 126
sp_UserOfflineSmall Offline
4
July 28, 2017 - 2:03 pm
sp_Permalink sp_Print

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

Avatar
jbeale1
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
5
July 28, 2017 - 10:36 pm
sp_Permalink sp_Print

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:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

winnieeq69

AutoCheernpen

Bostermet

engladNed

iivenul

olewaeayafaku

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee