【发布时间】:2017-09-27 21:27:17
【问题描述】:
我写了一个简短的脚本来显示一些图表:
if __name__=='__main__':
p1 = gen_spiral(label=0, dt=0, n_samples=100, )
p2 = gen_spiral(label=1, dt=np.pi, n_samples=100, )
print ("Array: {}\nType: {}\nShape: {}\nLength: {}\nData: {}\n".format("p1", type(p1), str(np.shape(p1)), len(p1), str(p1)))
print ("Array: {}\nType: {}\nShape: {}\nLength: {}\nData: {}\n".format("p2", type(p2), str(np.shape(p2)), len(p2), str(p2)))
a = np.arange(1,20,1)
b = np.arange(1,20,1)
c = np.arange(0.0, 2.0, 0.01)
d = np.sin(2*np.pi*c)
fig1 = plt.figure()
ax1 = fig1.add_subplot(121)
ax1.scatter(a,b)
ax2 = fig1.add_subplot(122)
ax2.scatter(c,d)
而且效果很好。但是,当我更改功能以显示我的数据时:
fig1 = plt.figure()
ax1 = fig1.add_subplot(121)
ax1.scatter(p1)
它给了我一个不应该存在的错误:
Traceback (most recent call last):
File "Theano--PlotSet--ME01.py", line 53, in <module>
ax1.scatter(p1)
TypeError: scatter() takes at least 3 arguments (2 given)
这不是真的:Scatter 有 3 个参数,而 p1 有两个部分:
jason@jason-HP-43299:~/Programs/MachineLearning/SectionOne$ python TheanoPS00.py
Array: p1
Type: <type 'numpy.ndarray'>
Shape: (100, 2)
Length: 100
Data: [[-0.0617 0.0534]
[ 0.0299 0.0913]
[ 0.0094 0.157 ]
[ 0.1057 0.1535]
[ 0.1412 0.2741]
[ 0.0851 0.1426]
这里到底发生了什么?
【问题讨论】:
-
如果 p1 有两个部分,您需要按照规范的要求将每个部分作为单独的位置参数传递:matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter
标签: python numpy matplotlib machine-learning theano