在此代码中,我的图表中的点在区间[-0.1;0.1]
中的高度不同,我如何更改我的图,因此点的宽度也会变化[-0.1:0.1]
?
grade是一个NxM numpy数组作为矩阵,随机放置数字[-3,00,2,4,7,10,12]
。
grades=grades[:,2:].T
# Changes so the dots vary i height
matrix = np.random.uniform(-0.1,0.1,grades.shape)
plotGrades = grades + matrix
# this line is relevant for another plot
mean=np.array(np.mean(grades,axis=1))
assignment=np.arange(1,1 + np.size(mean))
plt.figure(2, figsize=(15,20))
plt.xticks(range(len(grades)+1))
plt.yticks([-3,00,2,4,7,10,12])
plt.plot(assignment,plotGrades,'b.')
# This line are relevant for another plot
plt.plot(assignment,mean)
plt.title("Grades per assignment")
plt.xlabel("Assignments")
plt.ylabel("Grades")
plt.show()
答案 0 :(得分:0)
试试这个,如果我现在理解正确,它应该有效:
grades=grades[:,2:].T
#**Changes so the dots vary i height**
matrix = np.random.uniform(-0.1,0.1,grades.shape)
plotGrades = grades + matrix
#**this line is relevant for another plot**
mean=np.array(np.mean(grades,axis=1))
assignment=np.arange(1,1 + np.size(mean))
plt.figure(2, figsize=(15,20))
plt.xticks(range(len(grades)+1))
plt.yticks([-3,00,2,4,7,10,12])
matrix2 = np.random.uniform(-0.1,0.1,assignment.shape)
assignment2=assignment+matrix2
plt.plot(assignment2,plotGrades,'b.')
#**This line are relevant for another plot**
plt.plot(assignment,mean)
plt.title("Grades per assignment")
plt.xlabel("Assignments")
plt.ylabel("Grades")
plt.show()
答案 1 :(得分:0)
实际上,这应该有效:
grades=grades[:,2:].T
# Changes so the dots vary i height
matrix = np.random.uniform(-0.1,0.1,grades.shape)
plotGrades = grades + matrix
# this line is relevant for another plot
mean=np.array(np.mean(grades,axis=1))
assignment=np.arange(1,1 + np.size(mean))
plt.figure(2, figsize=(15,20))
plt.xticks(range(len(grades)+1))
plt.yticks([-3,0,2,4,7,10,12])
matrix2 = np.random.uniform(-0.1,0.1,(assignment.shape[0],1))
assignment2=assignment+matrix2
plt.plot(assignment2,plotGrades,'b.')
# This line are relevant for another plot
plt.plot(assignment,mean)
plt.title("Grades per assignment")
plt.xlabel("Assignments")
plt.ylabel("Grades")
plt.hold
plt.grid()
plt.show()
问题是assignment
尺寸为(3,)
并且:
matrix2 = np.random.uniform(-0.1,0.1,assignment.shape)
产生大小为3的1D向量,所有组件都等于相同的值。这就是为什么你在任何地方都有相同的价值。