Advertisement
Guest User

plot

a guest
Jun 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #loop through columns/assignments
  2. for i in range(2, np.size(grades, axis = 1)):
  3. #mean grade of each column/assignment
  4. y2.append(np.mean(grades[:,i]))
  5. #assignment number
  6. x2.append(i-1)
  7.  
  8. #loop through rows/students
  9. for j in range(np.size(grades,axis = 0)):
  10. #computing small random number to display how many students got the grade
  11. random_val=np.random.uniform(-0.1,0.1,1)
  12. #assignment plus small random value
  13. x=i-1+random_val
  14. #grade plus small random value
  15. y=grades[j,i]+random_val
  16. #plot grades as black dots/stars
  17. plt.plot( x, y,"k*")
  18.  
  19. #making plot with average trendline
  20. plt.plot(x2,y2,'r*', label = "Average grade")
  21. z = np.polyfit(x2, y2, 1) #plot
  22. p = np.poly1d(z) #
  23. plt.plot(x2,p(x2),"r--",label = "Average grade trendline")
  24.  
  25. #Plot
  26. #plt.plot(x,y,"b*", label='hgseljkgh') #plot
  27. plt.title("Grades per assignment")#title of the graph
  28. plt.legend(bbox_to_anchor=(1., 1.02, 0., .102), loc = "lower center")
  29. plt.xlabel("Assignments") #the x-axis label
  30. plt.ylabel("Grades") #the y-axis label
  31. plt.xlim() #the limits of the x-axis
  32. #y-axis limits is set from -4 to 13 to have a clearer view of the grades -3 and 12
  33. plt.ylim([-4, 13]) #the limits of the y-axis
  34. plt.grid() #show grid on graph
  35.  
  36. #show all plots
  37. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement