brewersfan1976

ch7-ex2.py

Aug 18th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # this program prints out ten different lines on a graph based
  2. # on a random number. The random number will be the y axis value
  3.  
  4. # import the python libraries for plotting
  5.  
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8.  
  9. # set x axis value to 50 to prevent the legend from covering up the first line
  10.  
  11. a = 50
  12.  
  13. # create the list to store the legend values
  14.  
  15. list = []
  16.  
  17. # loop through 10 times to create 10 separate lines on the graph
  18. # with random values between 30 and 300
  19.  
  20. for b in range(0, 10):
  21.     x = np.random.random_integers(30, 300)
  22.     y = np.arange(x)
  23.  
  24.     list.append(x)
  25.     plt.plot(y + a, y)
  26.  
  27.     a = a + 50
  28.  
  29.  
  30. # plot the legend on the graph in the upper left hand corner
  31.  
  32. plt.legend(list, loc = 'upper left')
  33.  
  34. # display the multi-line graph
  35.  
  36. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment