How can I make plot be drawn on top of the area? | MATLAB IoT Analytics | 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
How can I make plot be drawn on top of the area?
No permission to create posts
November 3, 2019
1:26 pm
Avatar
tml
New Member
Members
Forum Posts: 4
Member Since:
March 21, 2016
sp_UserOfflineSmall Offline

I've got a problem with my chart (https://thingspeak.com/apps/matlab_visualizations/275654) - the red plot is obscured by blue area despite calling the plot() function after area(). How can I change the order of the drawn data?

November 4, 2019
9:52 am
Avatar
cstapels
Moderator
Members


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

When I use the code below, my red line shows up over the area.
Can you share your code so we can see what is happening? There may be other ways to get the same visualization. Do the blue areas have a varying value, or are they just there to differentiate different regions of the plot?

y = [1 3 5; 3 2 7; 3 4 2];
area(y,'FaceColor','flat')
hold
plot(1:3,'r')

FYI, MATLAB answers is now the preferred location for ThingSpeak help and discussion.
https://www.mathworks.com/matlabcentral/answers/?product_base_code%5B%5D=ThingSpeak&sort=asked+desc

November 5, 2019
8:20 am
Avatar
tml
New Member
Members
Forum Posts: 4
Member Since:
March 21, 2016
sp_UserOfflineSmall Offline

Of course, here is a code:

readChannelID = nnnnnnn;
TemperatureFieldID = 1;
coolingFieldID = 2;

readAPIKey = 'XXXXXXXXXXXXXXXX';

[data, timeStamps] = thingSpeakRead(readChannelID, 'Fields',[TemperatureFieldID coolingFieldID], ...
'NumMinutes', 1440, ...
'ReadKey', readAPIKey);
temperatureData = data(:, 1);
coolingData = data(:, 2);

yyaxis right
h = area(timeStamps, coolingData, 'LineStyle','none');
h(1).FaceColor = [0.5 0.5 1];
ylabel('Cooling', 'Color',[0.5,0.5,1]);

yyaxis left
plot(timeStamps, temperatureData, 'Color',[1,0,0]);
ylabel('Temperature', 'Color',[1,0,0]);

November 5, 2019
2:40 pm
Avatar
cstapels
Moderator
Members


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

After your area plot, add the line
h.FaceAlpha = 0.2;

h = area(timeStamps, coolingData, 'LineStyle','none'); % your line already
h.FaceAlpha = 0.2; %add this line
h(1).FaceColor = [0.5 0.5 1]; %your line already

I edited the API key and channel number out of the post above, just for security.

November 5, 2019
4:34 pm
Avatar
tml
New Member
Members
Forum Posts: 4
Member Since:
March 21, 2016
sp_UserOfflineSmall Offline

Thank you, that works as it makes the area transparent and allows to "see" what lays underneath it.
My question though is how to make the plot drawn on top of the area chart. This is purely academic now as I have what I needed.

Thanks for hiding channel data, however I posted it deliberately so that anyone could test on my example and I didn't mind sharing the read (safe) key. But let it stay obscured.
Best Regards

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

titan83, Svetoslav, abubakar, shindepavan551@gmail.com, fet61-fakohse, Mario Marquez

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457