AMath 586, Spring Quarter 2019 at the University of Washington. For other notebooks, see Index.html or the Index of all notebooks on Github.
This notebook just illustrates a few things to make simple plots.
The following notebook "magic" command makes plots show up in the notebook in a manner that you can interact with them, e.g. zooming in. If you give plot commands in more than one cell you should close earlier figures before plotting new ones, or start each such cell with a figure command.
(Instead use %matplotlib inline to get them to show up in notebook but not be interactive.)
%matplotlib notebook
The next line imports many things from numpy and matplotlib, including things like pi, sin, linspace, and plot that are used below.
from pylab import *
x = linspace(0, 4*pi, 100)
y = x*x + x**3*sin(x)
Here is a plot of $f(x) = x^2 + x^3\sin(x)$.
figure(figsize=(6,4))
plot(x,y,'r')
Make another version that has different colored points and line.
Also save the result as a png file that can be downloaded.
x = linspace(0, 4*pi, 50)
y = x*x + x**3*sin(x)
figure(figsize=(6,4))
plot(x, y, 'r-')
plot(x, y, 'bo')
title('My plot')
grid(True)
savefig('myplot.png')
We can also display this png file (or any other image) inline:
from IPython.display import Image
Image('myplot.png')
See the matplotlib gallery for many examples.