Plot shows no line, only markers

조회 수: 5 (최근 30일)
Phillip Maus
Phillip Maus 2020년 9월 14일
댓글: Walter Roberson 2020년 9월 14일
Hello,
I want to plot two values from a thingspeak channel in a graph.
If I don't use any optional value for LineSpec, I can't see anything plotted although I don't get an error message and the values on x and y axis are in the correct range.
I f I ad for example a 'b.' (for blue points as markers) as LineSpec, I will see the markers but no line. If I ad an '-' for the solid line ('b.-' or 'b-') it doesn't show anything.
This seems very strange to me. I just want a solid line. How can I fix this? Many thanks!
This is my code:
readChannelID = [1....4];
fieldID1 = [1];
fieldID2 = [2];
readAPIKey = 'OA9........MQ';
[data1, time1] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 600, 'ReadKey', readAPIKey);
[data2, time2] = thingSpeakRead(readChannelID, 'Field', fieldID2, 'NumPoints', 600, 'ReadKey', readAPIKey);
yyaxis left;
plot(time1, data1,'r.')
% nothing is plotted if I use just use plot(time1, data1) or if I use plot(time1, data1,'r-')
yyaxis right;
plot(time2, data2, 'b.');

답변 (1개)

Steven Lord
Steven Lord 2020년 9월 14일
Do your time and/or data vectors contain NaN values?
any(isnan(time1))
any(isnan(time2))
any(isnan(data1))
any(isnan(data2))
Plotting data containing NaN values leaves a gap in the line where the NaN occurs.
x = 1:10;
y = 1:10;
x(3) = NaN;
y(7) = NaN;
plot(x, y)
With this example there will be a gap between 2 and 4 and between 6 and 8.
  댓글 수: 2
Phillip Maus
Phillip Maus 2020년 9월 14일
yes, I got it now.
There were missing values, I guess.
Fixed it using the fillmissing - function:
data1 = thingSpeakRead(1....9, 'NumDays', 1, 'ReadKey', 'O.............Q','OutputFormat','timetable');
cleanData1 = fillmissing(data1, 'previous');
yyaxis left;
plot(cleanData1.Timestamps, cleanData1.temp, 'b-');
yyaxis right;
plot(cleanData1.Timestamps, cleanData1.hum, 'r-');
Walter Roberson
Walter Roberson 2020년 9월 14일
Gaps are also left at infinite values.

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Visualize Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by