Graph line with different colors above and below a certain value | ThingSpeak API | Forum


Please consider registering


— 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
Graph line with different colors above and below a certain value

Forum Posts: 5
sp_UserOfflineSmall Offline
January 25, 2018 - 4:08 am
sp_Permalink sp_Print


I'm posting weather data to a few channels on ThingSpeak, for example this outdoor temperature:


I know how to change the color for the entire line in the graph, but since this is an outdoor temperature in Norway - where the temperature changes between above and below freezing on a regular basis - it would be really nice to have the graph line have different colors above and below freezing. Specifically, I would like it to be blue below 0 (freezing point on the Centigrade scale) and red above 0.

Any ideas how to do that?


Forum Posts: 257
sp_UserOfflineSmall Offline
January 26, 2018 - 12:06 am
sp_Permalink sp_Print

I dont know if any way to modify the thingspeak basic grapsh.  If you use a Matlab visualization you can sort your values into 2 series (above and below zero in your case) and plot them on the same graph with different colors.  


Hopefully someone with matlab skills can give us code for that..


Forum Posts: 62
sp_UserOfflineSmall Offline
January 26, 2018 - 3:49 pm
sp_Permalink sp_Print

Here is an example MATLAB code snippet to help you get started:

% Read data from your channel

[data, time] = thingSpeakRead(130083, 'NumPoints', 8000, 'Fields', 1);

% Create variables for holding values greater than zero and less than zero
dataGtZero = NaN(1, length(data));
dataLsZero = NaN(1, length(data));

% Assign values to the variables

% dataGtZero has all values of data that are greater than zero
dataGtZero(data>0) = data(data>0);

% dataLsZero has all values of data that are less than zero
dataLsZero(data<0) = data(data<0);

% Plot both chunks of data and specify color to be blue ('b') for data less than zero and red for the other.

plot(time, dataLsZero, 'b');
hold on;
plot(time, dataGtZero, 'r')

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
38 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:







Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565


Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee