Plotdevice,将json值转换为变量

时间:2016-04-27 17:02:31

标签: python 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。我怎样才能将椭圆形的锚定中心

谁能帮助我?提前致谢

1 个答案:

答案 0 :(得分:0)

oval()需要4个号码

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

但你有这条线

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

导致rstr(字符串类型,不是数字类型)

为什么不直接尝试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)