Skip to content

Instantly share code, notes, and snippets.

@mpilosov
Created August 25, 2017 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpilosov/b574191dcf6c577f277269047f531e30 to your computer and use it in GitHub Desktop.
Save mpilosov/b574191dcf6c577f277269047f531e30 to your computer and use it in GitHub Desktop.
Plotting example
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