选择一个有吸引力的线性比例为图形的Y轴 - 更多 [英] Choosing an attractive linear scale for a graph’s Y Axis - more

查看:141
本文介绍了选择一个有吸引力的线性比例为图形的Y轴 - 更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继:<一href="http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis">http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis

  

和做什么的一些观点时,   是消极的?

我相信这部分的问题没有得到回答,但似乎我不能评论或扩展的问题,所以我已经创建了一个新的

 值-100,0,100 5蜱:
 

  1. 下限= -100
  2. 上限= 100
  3. 范围= 100--100 = 200
  4. 在刻度范围= 40
    1. 除以10 ^ 2为0.4,转化为0.4,这给40(10 ^ 2相乘)。
  5. 在新下界= 40 *圆(-100/40)= -80
  6. 在新的上限= 40 *轮(1 +100 / 40)= 120

  1. 在新下界= 40 *楼(-100/40)= -120
  2. 在新的上限= 40 *地板(1 +100 / 40)= 120

现在的范围已经在40各增加至240(一个额外的滴答!),用5蜱。 这将需要6个步骤,以填补新的范围!

解决方案?

解决方案

我用下面的code。它产生于人类的观众很好地间隔的步骤和迎合穿过零范围。

公共静态类AxisUtil {     公共静态浮动CalculateStepSize(浮动范围,浮动targetSteps)     {         //计算在步长的初始猜测         浮tempStep =范围/ targetSteps;         //获取步长的大小         浮磁=(浮点)Math.Floor(Math.Log10(tempStep));         浮动magPow =(浮点)Math.Pow(10,MAG);         //计算新的步长的最显著位         浮magMsd =(int)的(tempStep / magPow + 0.5);         //促进来自MSD 1,2,或5         如果(magMsd&GT; 5.0)             magMsd = 10.0f;         否则,如果(magMsd&GT; 2.0)             magMsd = 5.0F;         否则,如果(magMsd&GT; 1.0)             magMsd = 2.0f;         返回magMsd * magPow;     } }

Further to: http://stackoverflow.com/questions/326679/choosing-an-attractive-linear-scale-for-a-graphs-y-axis

And what to do when some of the points are negative?

I believe this part of the question was not answered but it seems I can't comment or extend that question so I've created a new one

Values -100, 0, 100 with 5 ticks:

  1. lower bound = -100
  2. upper bound = 100
  3. range = 100--100 = 200
  4. tick range = 40

    1. Divide by 10^2 for 0.4, translates to 0.4, which gives (multiplied by 10^2) 40.

  5. new lower bound = 40 * round(-100/40) = -80
  6. new upper bound = 40 * round(1+100/40) = 120

or

  1. new lower bound = 40 * floor(-100/40) = -120
  2. new upper bound = 40 * floor(1+100/40) = 120

Now the range has been increased to 240 (an extra tick!), with 5 ticks at 40 each. it will take 6 steps to fill the new range!

Solution?

解决方案

I use the following code. It produces nicely-spaced steps for human viewers and caters for ranges that pass through zero.

public static class AxisUtil
{
    public static float CalculateStepSize(float range, float targetSteps)
    {
        // calculate an initial guess at step size
        float tempStep = range/targetSteps;

        // get the magnitude of the step size
        float mag = (float)Math.Floor(Math.Log10(tempStep));
        float magPow = (float)Math.Pow(10, mag);

        // calculate most significant digit of the new step size
        float magMsd = (int)(tempStep/magPow + 0.5);

        // promote the MSD to either 1, 2, or 5
        if (magMsd > 5.0)
            magMsd = 10.0f;
        else if (magMsd > 2.0)
            magMsd = 5.0f;
        else if (magMsd > 1.0)
            magMsd = 2.0f;

        return magMsd*magPow;
    }
}

这篇关于选择一个有吸引力的线性比例为图形的Y轴 - 更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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