Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. from __future__ import division, print_function # Always do this just to
  2. # ensure compatability
  3. # between python 2.7 and 3
  4. import matplotlib.pylab as P
  5.  
  6. # Always do these next to lines to enable LaTeX to be used on the
  7. # matplotlib plots
  8. P.rc('text', usetex=True)
  9. P.rc('font', family='serif')
  10.  
  11. x = P.linspace(0, 2, 15) # x is an array going from 0 to 2 evenly divided
  12. # into 15 points
  13.  
  14.  
  15. y_1 = x
  16. theta_i = x**2
  17. y_3_hat = P.sqrt(x)
  18.  
  19. P.plot(x, y_1, linewidth=2, color='red',
  20. label=r"$y_1$") # note that the `r` means "raw", and is needed if
  21. # you're using latex. Else, it's unnecessary.
  22.  
  23. P.plot(x, theta_i, linewidth=2, color='blue',
  24. label=r"$\theta_{i}$")
  25.  
  26. P.scatter(x, y_3_hat, linewidth=2, color='green',
  27. label=r"$\widehat{y}_3$") # I prefer `widehat` to `hat` xP
  28.  
  29. P.title("This is a test plot of 3 functions")
  30. P.xlabel(r"$x$-axis")
  31. P.ylabel("What even are these units?")
  32. P.legend() # Enables the legend that shows the labels you gave to each plot
  33.  
  34.  
  35. # Save the plot if you want
  36. P.savefig("example.eps") # eps is the best format for LaTeX. It's a vector
  37. # format, like SVG, so no quality gets lost. PNG
  38. # and other formats work as well
  39.  
  40. # Clear the plot if you want
  41. # P.clf()
  42.  
  43. # Show the plot if you want (note that this stops execution until you close
  44. # the plot)
  45. P.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement