【问题标题】:Octave line plot doesn't follow data points八度线图不遵循数据点
【发布时间】:2019-04-27 08:36:16
【问题描述】:

我正在尝试绘制适合数据集的函数,但线图未正确连接函数图上的点:(green points are original data, blue circles are points on the function and blue line should be connecting the blue circles.) 在我开始将毫秒从纪元转换为日期之后,问题似乎已经开始(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(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

【问题讨论】:

  • 如果不提供 MCVE,很难告诉您,但我猜您会因为 OpenGL 中的单精度浮点计算而看到这一点。尝试减去第一个元素 vor 切换到 Gnuplot 作为绘图后端
  • 请阅读minimal reproducible example(安迪提到的MCVE)。
  • 可能与这个问题有关:stackoverflow.com/q/53229703/4183191
  • @Andy 哦,我将添加 MCVE。谢谢!
  • @TasosPapastylianou 谢谢,确实如此。

标签: octave


【解决方案1】:

让它像这样工作:

 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    相关资源
    最近更新 更多