我想在python中使用ginput
函数从图中获取两个点并获得最接近的int值并保存数组。代码如下所示:
from __future__ import print_function
from pylab import plot, ginput, show, axis
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(10)
plt.plot(t, np.sin(t))
print("Please click")
x = ginput(2)
x=np.ceil(x)
**print (x)**
plt.show()
当我运行代码并用括号打印x时,输出为:
Please click
[[ 2. 1.]
[ 8. -0.]]
但是,如果我运行代码并打印x
而没有括号,
from __future__ import print_function
from pylab import plot, ginput, show, axis
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(10)
plt.plot(t, np.sin(t))
print("Please click")
x = ginput(2)
x=np.ceil(x)
**print x**
plt.show()
输出显示错误:
File "<ipython-input-27-1d992b01e790>", line 1
print x
^
SyntaxError: invalid syntax
我对此感到很困惑。这是什么原因?