2016-06-08 80 views
2

我想在位圖編輯器中逐像素地重繪此Body Weight比例。據我瞭解這是一個對數尺度,但什麼是對數 - 二進制或十進制?以對數刻度計算值

如何計算以像素爲單位的行之間的距離。也許最好從1到70算起,而不是倒過來。

values = [] 
for kilos, value in enumerate(range(1, 71)): 
    // some logic 
    values.append([kilos, pixels]) 
reverse(values) 

enter image description here

+2

由於從10到20的距離與從20到40的距離相同,因此我將冒險猜測Log 2. – cdlane

+3

由於log_n(a)= log(a)/ log(n),基地並不重要。 – kennytm

回答

1

假設你想在500像素的高度,你可以用它來獲得區間:

import math 
pixels = 500 
offset = math.log(10) 
for x in range(10, 71, 10): 
    print x, int(pixels * (math.log(x) - offset)/(math.log(70) - offset)) 

這是輸出:

10 0 
20 178 
30 282 
40 356 
50 413 
60 460 
70 500 

像素數只是每個間隔的開始和結束之間的差異。更改500以適合您的應用程序。