2016-04-27 68 views
1


我有以下代碼:Plotdevice,將JSON值到變量

size(297,420) 
weather = read("january_2016.json", dict=adict) 
print "(in january 2016 the min temperature was %i)" % weather.MaxTemperature.min 

r = "%i" %weather.MaxTemperature.min 

nofill() 
stroke(.1) 

print r 
oval(10,10,r,r) 

,但我這裏有兩個問題:
1.當我想用橢圓形(10,10,r,r)我出現以下錯誤:

DeviceError: Invalid coordinates (looking for ['Point', 'Size'], got ['Point', 'str', 'str']) 

2.我怎麼能中心的橢圓形的錨

誰能幫米出去?在此先感謝

回答

0

oval()需要4個數字

oval(x, y, width, height, plot=True, **style) 

但是你此行

r = "%i" % weather.MaxTemperature.min 

它導致r是一個str(字符串類型,而不是一個數值型)

爲什麼不直接嘗試r = weather.MaxTemperature.min,因爲它可能是一個數字

r = weather.MaxTemperature.min 
# or if that value isn't numeric, try converting it to a float 
# r = float(r) 

... 
oval(10, 10, r, r) 
+0

太棒了!非常感謝! – shirinmalina