给定数值范围的1-2-5-刻度标签坐标轴 [英] label coordinate axis with 1-2-5-ticks for given numeric range

查看:156
本文介绍了给定数值范围的1-2-5-刻度标签坐标轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个不太清晰的问题

  gnuplot>设置xrange [0:2] 
gnuplot>设置yrange [0:exp(2)]
gnuplot>情节exp(x)

  gnuplot>设置yrange [0:exp(5)] 
gnuplot>设置xrange [0:5]
gnuplot>情节exp(x)

  gnuplot>设置yrange [0:exp(10)] 
gnuplot>设置xrange [0:10]
gnuplot>情节exp(x)



要实施这样的标记方案,
如何找到给定范围内的理想1-2-5-tick距离?

(采用伪代码或JavaScript或Python等常用语言)

解决方案

要从范围 0..max )获得这些1-2-5-tick方案之一,我们必须将数量级(指数)和数字(尾数)分开,并找到最合适的数字(1 、、 2或5)小于或等于代表的最高有效位。



参见此类函数在JavaScript中:

  //找到给定范围的1-2-5-tick距离
函数tick_distance(range){
让fin d_factor = function(v){
if(v> = 5){
v = 5;
}否则,如果(v> = 2){
v = 2;
}否则,如果(v> = 1){
v = 1;
}
return v;
};

让代表=范围* 0.24
让l10 = Math.log10(代表);
let指数= Math.floor(l10);
让尾数= 10指数;
let realdist = Math.pow(10,尾数);
let factor = find_factor(realdist);
let dist = factor * Math.pow(10,指数);
return dist;
}

启发式因子 0.24 代表的c>在变化的数量级上给出的滴答计数在4到10之间; 0.23 也可以,而 0.25 仅在 2 *的范围内最多提供10个刻度10 ^ n




  • 0.22 有时会给出11 ticks

  • 2.26 有时会给出3个ticks



我承认我自己对此因素的确切价值感兴趣。


The somewhat unclear question Exponential Graph Animation P5js Canvas contains an interesting detail about programmatically labeling axes for a broad variety of ranges. I instantly remembered that gnuplot does what I searched for. By interactively zooming in the preview window (and without any particular ticks specification), I observed that it automatically selects a labeling scheme with an amount of between 4 and 10 ticks and a fixed distance of 1, 2, or 5 times some power of 10.

The following 4 examples can be taken as snapshots of this interactive process.

gnuplot> set xrange [0:1]
gnuplot> set yrange [0:exp(1)]
gnuplot> plot exp(x)

gnuplot> set xrange [0:2]
gnuplot> set yrange [0:exp(2)]
gnuplot> plot exp(x)

gnuplot> set yrange [0:exp(5)]
gnuplot> set xrange [0:5]
gnuplot> plot exp(x)

gnuplot> set yrange [0:exp(10)]
gnuplot> set xrange [0:10]
gnuplot> plot exp(x)

To implement such a labeling scheme, how do I find the ideal 1-2-5-tick distance for a given range?
(in pseudo code or some usual language like JavaScript or Python)

解决方案

To get one of these 1-2-5-tick schemes from a range (0..max), we have to separate order of magnitude (exponent) and digits (mantissa), and to find the most appropriate digit (1, 2, or 5) below or equal to the most significant digit of a representative.

See such a function in JavaScript:

// find 1-2-5-tick distance for a given range
function tick_distance(range) {
  let find_factor = function(v) {
    if (v >= 5) {
      v = 5;
    } else if (v >= 2) {
      v = 2;
    } else if (v >= 1) {
      v = 1;
    }
    return v;
  };

  let representative = range * 0.24
  let l10 = Math.log10(representative);
  let exponent = Math.floor(l10);
  let mantissa = l10-exponent;
  let realdist = Math.pow(10, mantissa);
  let factor = find_factor(realdist);
  let dist = factor * Math.pow(10, exponent);
  return dist;
}

The heuristic factor of 0.24 for the representative gives tick counts between 4 and 10 over changing orders of magnitude; 0.23 would also work whereas 0.25 provides the maximum of 10 ticks only for ranges of 2*10^n.

  • 0.22 gives sometimes 11 ticks
  • 2.26 gives sometimes 3 ticks

I admit that I'm myself am interested in the "exact value" for this factor.

这篇关于给定数值范围的1-2-5-刻度标签坐标轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆