Skip to content

Instantly share code, notes, and snippets.

@Atlas7
Created May 21, 2017 14:16
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 Atlas7/6371d6a83aa72c15b3e160adcffcdbb4 to your computer and use it in GitHub Desktop.
Save Atlas7/6371d6a83aa72c15b3e160adcffcdbb4 to your computer and use it in GitHub Desktop.
sample_jupyter_notebook_plot.py
# clean up kernel
%reset -f
# This is a bit of magic to make matplotlib figures appear inline in the notebook
# rather than in a new window.
%matplotlib inline
# Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
import numpy as np
import matplotlib.pyplot as plt
n = 256
X = np.linspace(-np.pi, np.pi, n, endpoint=True)
Y = np.sin(2 * X)
plt.axes([0.025, 0.025, 0.95, 0.95])
plt.plot(X, Y + 1, color='blue', alpha=1.00)
plt.fill_between(X, 1, Y + 1, color='blue', alpha=.25)
plt.plot(X, Y - 1, color='blue', alpha=1.00)
plt.fill_between(X, -1, Y - 1, (Y - 1) > -1, color='blue', alpha=.25)
plt.fill_between(X, -1, Y - 1, (Y - 1) < -1, color='red', alpha=.25)
plt.xlim(-np.pi, np.pi)
plt.xticks(())
plt.ylim(-2.5, 2.5)
plt.yticks(())
plt.show()
@Atlas7
Copy link
Author

Atlas7 commented May 21, 2017

Use in this Stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment