2009-10-06 24 views
1

繼:Choosing an attractive linear scale for a graph's Y Axis選擇一個有吸引力的線性度的圖表的Y軸 - 更多

而當一些觀點 的是消極的做什麼?

我相信這部分的質詢沒有得到回答,但似乎我無法評論或延長這個問題,所以我已經創建了一個新的

Values -100, 0, 100 with 5 ticks: 
  1. 下限= -100
  2. 上限= 100
  3. 範圍= 100--100 = 200
  4. 蜱範圍= 40
    1. 除以10^2爲0.4,轉換爲0.4,其給出40
  5. 新下界= 40 *輪(-100/40)= -80
  6. (10^2相乘)
  7. 新上限= 40 *輪(1 +四十零分之百)= 120

  • 新下界= 40 *地板(-100/40) = -120
  • 新的上限= 40 * flo或(1 + 100/40)= 120
  • 現在範圍增加到240(一個額外的滴答!),每個40個滴答5個滴答。 它將需要6個步驟來填補新的範圍!

    解決方案?

    回答

    0

    我使用下面的代碼。它爲人類觀衆提供了很好的間隔步驟,並且滿足了通過零的範圍。

    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; 
        } 
    } 
    
    +0

    我看到它返回一個步驟值,你用什麼作爲軸的起始值? – McBainUK 2009-10-06 13:01:17

    +0

    我會使用零,並從那裏工作,直到你的範圍被覆蓋。這將給你很好的步驟,易於閱讀和彙總成一個可理解的系列(例如,想象由0.25/0.5/1/2/5/10/25/50/100/250/etc中的每一個創建的系列反覆添加)。 – 2009-10-06 13:11:24