鉴于数据的范围,需要巧妙的算法来计算的图形轴刻度粒度粒度、刻度、算法、巧妙

2023-09-12 21:23:59 作者:染指丶妃子笑

方案:

在绘制图形。有数据点,其范围从A到B,并要确定一个粒度绘制轴刻度。例如,对于134到151的规模可能会遇到从130到155,开始和结束的十进位制圆的数字。但数字可能从134.31运行134.35,在这种情况下,范围从130至135将(目视)的COM preSS的出在数据中的意义 - 这将是更好画出刻度从134至135 ,甚至可能在134.3至134.4。而数据的值可能不是从0.013431运行0.013435,或从1343100到1343500。

Drawing a graph. Have data points which range from A to B, and want to decide on a granularity for drawing the axis scales. Eg, for 134 to 151 the scale might run from 130 to 155, to start and end on "round" numbers in the decimal system. But the numbers might run from 134.31 to 134.35, in which case a scale from 130 to 135 would (visually) compress out the "significance" in the data -- it would be better to draw the scale from 134 to 135, or maybe even 134.3 to 134.4. And the data values might instead run from 0.013431 to 0.013435, or from 1343100 to 1343500.

所以我试图找出一种优雅的方式来计算的粒度舍低势必下降到和上限达,产生一个赏心悦目的图表。人们可以只是砍它在某种程度上,但几乎不产生信心,奇的情况下将处理好的。

So I'm trying to figure out an elegant way to calculate the "granularity" to round the low bound down to and the upper bound up to, to produce a "pleasing" chart. One could just "hack" it somehow, but that produces little confidence that "odd" cases will be handled well.

任何想法?

推荐答案

只是一个想法:

在加入约10%的范围内,调整这个数字凭经验 的范围内剔数除以你想要的大小有标记 以10为底,这个数字的 乘以3的结果,然后舍入到最接近的整数 在其余模3会告诉你,你是否希望至少显著小数步长为1,2,或5 更改 在整数除以3的结果会告诉你十的力量,用 乘坐(扩展)范围,并计算其包含的极值剔点,根据刻度frequencey只是计算 确保所有的数据点是在于在该范围内,加上蜱如果不是 如果需要,通过降低上述整数加法次刻度由一个 Add about 10% to your range, tune this figure empirically Divide size of range by number of tick marks you want to have Take the base 10 logarithm of that number Multiply the result by three, then round to the nearest integer The remainder modulo 3 will tell you whether you want the least significant decimal to change in steps of 1, 2, or 5 The result of an integer division by 3 will tell you the power of ten to use Take the (extended) range and compute the extremal tick points it contains, according to the tick frequencey just computed Ensure that all data points actually lie within that range, add ticks if not If needed, add minor ticks by decreasing the integer above by one