Advertisement
miszczo

python plot

May 30th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1.  
  2.  
  3.  
  4. fig, ax = plt.subplots()
  5.  
  6. # Fixing random state for reproducibility
  7. np.random.seed(19680801)
  8.  
  9.  
  10. # histogram our data with numpy
  11.  
  12. data = np.random.randn(1000)
  13. n, bins = np.histogram(data, 50)
  14.  
  15. # get the corners of the rectangles for the histogram
  16. left = np.array(bins[:-1])
  17. right = np.array(bins[1:])
  18. bottom = np.zeros(len(left))
  19. top = bottom + n
  20.  
  21.  
  22. # we need a (numrects x numsides x 2) numpy array for the path helper
  23. # function to build a compound path
  24. XY = np.array([[left, left, right, right], [bottom, top, top, bottom]]).T
  25.  
  26. # get the Path object
  27. barpath = path.Path.make_compound_path_from_polys(XY)
  28.  
  29. # make a patch out of it
  30. patch = patches.PathPatch(barpath)
  31. ax.add_patch(patch)
  32.  
  33. # update the view limits
  34. ax.set_xlim(left[0], right[-1])
  35. ax.set_ylim(bottom.min(), top.max())
  36.  
  37. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement