开发者

Auto inferring scale for a time series plot

开发者 https://www.devze.com 2022-12-21 17:21 出处:网络
Problem: I am plotting a time series. I don\'t know apriori the minimum & maximum values. I want to plot it for the last 5 seconds of data. I want the plot to automaticaly rescale itself to best

Problem:

I am plotting a time series. I don't know apriori the minimum & maximum values. I want to plot it for the last 5 seconds of data. I want the plot to automaticaly rescale itself to best fit the data for the past five seconds. However, I don't want the rescaling to be jerky (as one would get by constantly resetting the min & max) -- when it does rescale, I want the rescaling to be smooth.

Are ther开发者_StackOverflowe any existing algorithms for handling this?

Formally:

I have a function

float sample();

that you can call multiple times. I want you to constantly, in real time, plot the last 5 * 60 values to me, with the chart nicely scaled. I want the chart to automatically rescale; but not in a "jerky" way.

Thanks!


You could try something like

 float currentScale = 0;
 float adjustSpeed = .3f;

 void iterate() {

       float targetScale = sample();
       currentScale += adjustSpeed * (targetScale - currentScale);

 }

And lower the adjustSpeed if it's too jerky.

0

精彩评论

暂无评论...
验证码 换一张
取 消