Created
August 25, 2017 03:07
-
-
Save mpilosov/b574191dcf6c577f277269047f531e30 to your computer and use it in GitHub Desktop.
Plotting example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib import pyplot as plt # imports plotting library, uses 'plt' as the handle. for help, google "matplotlib" | |
x = np.linspace(-1, 1, 100) | |
y = x.**2 + 2.*x + 1 | |
plt.figure() # open a new figure (sometimes you see ax, fig = plt.figure() if people want to instantiate multiple figures. | |
plt.plot(x,y) | |
plt.xlabel("x axis") | |
plt.ylabel("y axis") | |
plt.title("Here is a plot.") | |
plt.savefig("name_of_file.png") # save it to file | |
# plt.show() # this will make it open as a figure that you can look at -- optional | |
plt.cla() # now that you've saved it, clear it out to be efficient with memory. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment