Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division, print_function # Always do this just to
- # ensure compatability
- # between python 2.7 and 3
- import matplotlib.pylab as P
- # Always do these next to lines to enable LaTeX to be used on the
- # matplotlib plots
- P.rc('text', usetex=True)
- P.rc('font', family='serif')
- x = P.linspace(0, 2, 15) # x is an array going from 0 to 2 evenly divided
- # into 15 points
- y_1 = x
- theta_i = x**2
- y_3_hat = P.sqrt(x)
- P.plot(x, y_1, linewidth=2, color='red',
- label=r"$y_1$") # note that the `r` means "raw", and is needed if
- # you're using latex. Else, it's unnecessary.
- P.plot(x, theta_i, linewidth=2, color='blue',
- label=r"$\theta_{i}$")
- P.scatter(x, y_3_hat, linewidth=2, color='green',
- label=r"$\widehat{y}_3$") # I prefer `widehat` to `hat` xP
- P.title("This is a test plot of 3 functions")
- P.xlabel(r"$x$-axis")
- P.ylabel("What even are these units?")
- P.legend() # Enables the legend that shows the labels you gave to each plot
- # Save the plot if you want
- P.savefig("example.eps") # eps is the best format for LaTeX. It's a vector
- # format, like SVG, so no quality gets lost. PNG
- # and other formats work as well
- # Clear the plot if you want
- # P.clf()
- # Show the plot if you want (note that this stops execution until you close
- # the plot)
- P.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement