Octave line plot doesn't follow data points












0















I'm trying to plot a function I fitted to a dataset, but the line plot does not connect the points on the function's graph correctly:(green points are original data, blue circles are points on the function and blue line should be connecting the blue circles.) The problem seems to have begun after I started converting milliseconds from epoch to date (x-axis).



%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp(1:end-1), f);
endfor
%

%convert millis since epoch to days since 0000 (now for the training set examples)
timeVecXX = zeros(size(XX,1), 1);

for i = 1:size(XX,1)
timeTmp = ctime(XX(i)/1000);
timeVecXX(i) = datenum(timeTmp(1:end-1), f);
endfor
%

hold("off");
plot(timeVec, plotFunc(x), '-ob');
datetick("ddd mmm dd");
hold("on");
grid on;
plot(timeVecXX,yy, '.g');


MCVE:



optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
optimA = 78250000;
mu = [1.5431e+012, 5.8217e-003];
s = [2.4831e+007, 7.1022e-001];

plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2) %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

x = [1543076107026:(linZero-1543076107026)/100:linZero];
x = x';

%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy ";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp, f);
endfor
%

hold("on");
plot(timeVec, plotFunc(x), 'o-b');
datetick("ddd mmm dd");
grid on;
xlabel ("Day");
hold("off");




function [y] = predict (X, theta, mu, s, a)

Xtemp = [X, sin((X-a)/(1000*60*60*24/(2*pi)))];
Xtemp = (Xtemp-mu)./s;
Xtemp = [ones(size(Xtemp,1),1), Xtemp];

y = Xtemp*theta;

endfunction









share|improve this question




















  • 1





    Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

    – Andy
    Nov 25 '18 at 15:20











  • Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

    – Cris Luengo
    Nov 25 '18 at 15:41













  • may be related to this question: stackoverflow.com/q/53229703/4183191

    – Tasos Papastylianou
    Nov 25 '18 at 16:01











  • @Andy Oh, I'll add the MCVE. Thanks!

    – Auruttch
    Nov 25 '18 at 16:06






  • 1





    @TasosPapastylianou Thanks, it is indeed.

    – Auruttch
    Nov 25 '18 at 16:53
















0















I'm trying to plot a function I fitted to a dataset, but the line plot does not connect the points on the function's graph correctly:(green points are original data, blue circles are points on the function and blue line should be connecting the blue circles.) The problem seems to have begun after I started converting milliseconds from epoch to date (x-axis).



%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp(1:end-1), f);
endfor
%

%convert millis since epoch to days since 0000 (now for the training set examples)
timeVecXX = zeros(size(XX,1), 1);

for i = 1:size(XX,1)
timeTmp = ctime(XX(i)/1000);
timeVecXX(i) = datenum(timeTmp(1:end-1), f);
endfor
%

hold("off");
plot(timeVec, plotFunc(x), '-ob');
datetick("ddd mmm dd");
hold("on");
grid on;
plot(timeVecXX,yy, '.g');


MCVE:



optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
optimA = 78250000;
mu = [1.5431e+012, 5.8217e-003];
s = [2.4831e+007, 7.1022e-001];

plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2) %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

x = [1543076107026:(linZero-1543076107026)/100:linZero];
x = x';

%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy ";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp, f);
endfor
%

hold("on");
plot(timeVec, plotFunc(x), 'o-b');
datetick("ddd mmm dd");
grid on;
xlabel ("Day");
hold("off");




function [y] = predict (X, theta, mu, s, a)

Xtemp = [X, sin((X-a)/(1000*60*60*24/(2*pi)))];
Xtemp = (Xtemp-mu)./s;
Xtemp = [ones(size(Xtemp,1),1), Xtemp];

y = Xtemp*theta;

endfunction









share|improve this question




















  • 1





    Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

    – Andy
    Nov 25 '18 at 15:20











  • Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

    – Cris Luengo
    Nov 25 '18 at 15:41













  • may be related to this question: stackoverflow.com/q/53229703/4183191

    – Tasos Papastylianou
    Nov 25 '18 at 16:01











  • @Andy Oh, I'll add the MCVE. Thanks!

    – Auruttch
    Nov 25 '18 at 16:06






  • 1





    @TasosPapastylianou Thanks, it is indeed.

    – Auruttch
    Nov 25 '18 at 16:53














0












0








0








I'm trying to plot a function I fitted to a dataset, but the line plot does not connect the points on the function's graph correctly:(green points are original data, blue circles are points on the function and blue line should be connecting the blue circles.) The problem seems to have begun after I started converting milliseconds from epoch to date (x-axis).



%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp(1:end-1), f);
endfor
%

%convert millis since epoch to days since 0000 (now for the training set examples)
timeVecXX = zeros(size(XX,1), 1);

for i = 1:size(XX,1)
timeTmp = ctime(XX(i)/1000);
timeVecXX(i) = datenum(timeTmp(1:end-1), f);
endfor
%

hold("off");
plot(timeVec, plotFunc(x), '-ob');
datetick("ddd mmm dd");
hold("on");
grid on;
plot(timeVecXX,yy, '.g');


MCVE:



optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
optimA = 78250000;
mu = [1.5431e+012, 5.8217e-003];
s = [2.4831e+007, 7.1022e-001];

plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2) %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

x = [1543076107026:(linZero-1543076107026)/100:linZero];
x = x';

%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy ";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp, f);
endfor
%

hold("on");
plot(timeVec, plotFunc(x), 'o-b');
datetick("ddd mmm dd");
grid on;
xlabel ("Day");
hold("off");




function [y] = predict (X, theta, mu, s, a)

Xtemp = [X, sin((X-a)/(1000*60*60*24/(2*pi)))];
Xtemp = (Xtemp-mu)./s;
Xtemp = [ones(size(Xtemp,1),1), Xtemp];

y = Xtemp*theta;

endfunction









share|improve this question
















I'm trying to plot a function I fitted to a dataset, but the line plot does not connect the points on the function's graph correctly:(green points are original data, blue circles are points on the function and blue line should be connecting the blue circles.) The problem seems to have begun after I started converting milliseconds from epoch to date (x-axis).



%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp(1:end-1), f);
endfor
%

%convert millis since epoch to days since 0000 (now for the training set examples)
timeVecXX = zeros(size(XX,1), 1);

for i = 1:size(XX,1)
timeTmp = ctime(XX(i)/1000);
timeVecXX(i) = datenum(timeTmp(1:end-1), f);
endfor
%

hold("off");
plot(timeVec, plotFunc(x), '-ob');
datetick("ddd mmm dd");
hold("on");
grid on;
plot(timeVecXX,yy, '.g');


MCVE:



optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
optimA = 78250000;
mu = [1.5431e+012, 5.8217e-003];
s = [2.4831e+007, 7.1022e-001];

plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2) %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

x = [1543076107026:(linZero-1543076107026)/100:linZero];
x = x';

%convert millis since epoch to days since 0000
timeVec = zeros(size(x,1), 1);
f = "ddd mmm dd HH:MM:SS yyyy ";

for i = 1:size(x,1)
timeTmp = ctime(x(i)/1000);
timeVec(i) = datenum(timeTmp, f);
endfor
%

hold("on");
plot(timeVec, plotFunc(x), 'o-b');
datetick("ddd mmm dd");
grid on;
xlabel ("Day");
hold("off");




function [y] = predict (X, theta, mu, s, a)

Xtemp = [X, sin((X-a)/(1000*60*60*24/(2*pi)))];
Xtemp = (Xtemp-mu)./s;
Xtemp = [ones(size(Xtemp,1),1), Xtemp];

y = Xtemp*theta;

endfunction






octave






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 16:27







Auruttch

















asked Nov 25 '18 at 14:38









AuruttchAuruttch

113




113








  • 1





    Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

    – Andy
    Nov 25 '18 at 15:20











  • Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

    – Cris Luengo
    Nov 25 '18 at 15:41













  • may be related to this question: stackoverflow.com/q/53229703/4183191

    – Tasos Papastylianou
    Nov 25 '18 at 16:01











  • @Andy Oh, I'll add the MCVE. Thanks!

    – Auruttch
    Nov 25 '18 at 16:06






  • 1





    @TasosPapastylianou Thanks, it is indeed.

    – Auruttch
    Nov 25 '18 at 16:53














  • 1





    Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

    – Andy
    Nov 25 '18 at 15:20











  • Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

    – Cris Luengo
    Nov 25 '18 at 15:41













  • may be related to this question: stackoverflow.com/q/53229703/4183191

    – Tasos Papastylianou
    Nov 25 '18 at 16:01











  • @Andy Oh, I'll add the MCVE. Thanks!

    – Auruttch
    Nov 25 '18 at 16:06






  • 1





    @TasosPapastylianou Thanks, it is indeed.

    – Auruttch
    Nov 25 '18 at 16:53








1




1





Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

– Andy
Nov 25 '18 at 15:20





Without providing a MCVE it's hard to tell you but I guess you are seeing this due to single.precision floating point calculations in OpenGL. Try to substract the first element vor switch to Gnuplot as plotting backend

– Andy
Nov 25 '18 at 15:20













Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

– Cris Luengo
Nov 25 '18 at 15:41







Please read Minimal, Complete, and Verifiable example (the MCVE that Andy referred to).

– Cris Luengo
Nov 25 '18 at 15:41















may be related to this question: stackoverflow.com/q/53229703/4183191

– Tasos Papastylianou
Nov 25 '18 at 16:01





may be related to this question: stackoverflow.com/q/53229703/4183191

– Tasos Papastylianou
Nov 25 '18 at 16:01













@Andy Oh, I'll add the MCVE. Thanks!

– Auruttch
Nov 25 '18 at 16:06





@Andy Oh, I'll add the MCVE. Thanks!

– Auruttch
Nov 25 '18 at 16:06




1




1





@TasosPapastylianou Thanks, it is indeed.

– Auruttch
Nov 25 '18 at 16:53





@TasosPapastylianou Thanks, it is indeed.

– Auruttch
Nov 25 '18 at 16:53












1 Answer
1






active

oldest

votes


















1














Got it working like this:



 optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
optimA = 78250000;
mu = [1.5431e+012, 5.8217e-003];
s = [2.4831e+007, 7.1022e-001];

plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2); %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

tOffset = 1543076107026;

x = [1543076107026:(linZero-1543076107026)/100:linZero];
x = x';

timeVec = x-tOffset;

xTicks = [-65707026:(24*60*60*1000):539092974];

hold("on");
set(gca, 'xtick', xTicks);
plot(timeVec, plotFunc(x), '-ob');

lTVec = ;
for i=1:size(xTicks,2)
lTVec = [lTVec; strftime("%a %b %d", localtime((xTicks(i)+tOffset)/1000))];
endfor


set(gca, 'xticklabel', lTVec);
grid on;
xlabel ("Day");
hold("off");


graph






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468582%2foctave-line-plot-doesnt-follow-data-points%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Got it working like this:



     optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
    optimA = 78250000;
    mu = [1.5431e+012, 5.8217e-003];
    s = [2.4831e+007, 7.1022e-001];

    plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

    linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2); %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

    tOffset = 1543076107026;

    x = [1543076107026:(linZero-1543076107026)/100:linZero];
    x = x';

    timeVec = x-tOffset;

    xTicks = [-65707026:(24*60*60*1000):539092974];

    hold("on");
    set(gca, 'xtick', xTicks);
    plot(timeVec, plotFunc(x), '-ob');

    lTVec = ;
    for i=1:size(xTicks,2)
    lTVec = [lTVec; strftime("%a %b %d", localtime((xTicks(i)+tOffset)/1000))];
    endfor


    set(gca, 'xticklabel', lTVec);
    grid on;
    xlabel ("Day");
    hold("off");


    graph






    share|improve this answer






























      1














      Got it working like this:



       optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
      optimA = 78250000;
      mu = [1.5431e+012, 5.8217e-003];
      s = [2.4831e+007, 7.1022e-001];

      plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

      linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2); %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

      tOffset = 1543076107026;

      x = [1543076107026:(linZero-1543076107026)/100:linZero];
      x = x';

      timeVec = x-tOffset;

      xTicks = [-65707026:(24*60*60*1000):539092974];

      hold("on");
      set(gca, 'xtick', xTicks);
      plot(timeVec, plotFunc(x), '-ob');

      lTVec = ;
      for i=1:size(xTicks,2)
      lTVec = [lTVec; strftime("%a %b %d", localtime((xTicks(i)+tOffset)/1000))];
      endfor


      set(gca, 'xticklabel', lTVec);
      grid on;
      xlabel ("Day");
      hold("off");


      graph






      share|improve this answer




























        1












        1








        1







        Got it working like this:



         optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
        optimA = 78250000;
        mu = [1.5431e+012, 5.8217e-003];
        s = [2.4831e+007, 7.1022e-001];

        plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

        linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2); %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

        tOffset = 1543076107026;

        x = [1543076107026:(linZero-1543076107026)/100:linZero];
        x = x';

        timeVec = x-tOffset;

        xTicks = [-65707026:(24*60*60*1000):539092974];

        hold("on");
        set(gca, 'xtick', xTicks);
        plot(timeVec, plotFunc(x), '-ob');

        lTVec = ;
        for i=1:size(xTicks,2)
        lTVec = [lTVec; strftime("%a %b %d", localtime((xTicks(i)+tOffset)/1000))];
        endfor


        set(gca, 'xticklabel', lTVec);
        grid on;
        xlabel ("Day");
        hold("off");


        graph






        share|improve this answer















        Got it working like this:



         optimTheta = [8.0916e+004; -3.4102e+003; 7.5091e+003];
        optimA = 78250000;
        mu = [1.5431e+012, 5.8217e-003];
        s = [2.4831e+007, 7.1022e-001];

        plotFunc = @(p) predict(p,optimTheta,mu,s,optimA);

        linZero = -(optimTheta(1)*s(1)-optimTheta(2)*mu(1))/optimTheta(2); %solution for the equation theta0 + theta1*(x-mu(1))/s(1) = 0

        tOffset = 1543076107026;

        x = [1543076107026:(linZero-1543076107026)/100:linZero];
        x = x';

        timeVec = x-tOffset;

        xTicks = [-65707026:(24*60*60*1000):539092974];

        hold("on");
        set(gca, 'xtick', xTicks);
        plot(timeVec, plotFunc(x), '-ob');

        lTVec = ;
        for i=1:size(xTicks,2)
        lTVec = [lTVec; strftime("%a %b %d", localtime((xTicks(i)+tOffset)/1000))];
        endfor


        set(gca, 'xticklabel', lTVec);
        grid on;
        xlabel ("Day");
        hold("off");


        graph







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 25 '18 at 19:11

























        answered Nov 25 '18 at 16:56









        AuruttchAuruttch

        113




        113
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468582%2foctave-line-plot-doesnt-follow-data-points%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Futebolista

            Feedback on college project

            Albești (Vaslui)