Or wackywendell.github.io/learntocode
Python is a full-featured language for generic programming, and data analysis, and it can also make beautiful plots. I made this plot last week. It took about 20-40 lines of code!
ipython notebookEnterThe IPython Notebook is running at: http://localhost:8888/Ctrl-Click if necessary.New, and under Notebooks click Python 3.%pylab inline
Populating the interactive namespace from numpy and matplotlib
# This is hidden in the slides, but makes the plots small enough to fit in a slide
import matplotlib
phi = (1 + np.sqrt(5)) / 2.
matplotlib.rc('figure', figsize=(3,3/phi))
xs = np.linspace(0, np.pi*2)
ys = np.sin(xs)
plot(xs, ys)
[<matplotlib.lines.Line2D at 0x7f3f2a684cc0>]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-18-ec77aff7bf8c> in <module>()
----> 1 plot([1,2,3,4,5,6,7,8,9,10], [1,4,8,2,3,5,8,9,3,6,7])
/usr/lib/python3.5/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
3097 ax.hold(hold)
3098 try:
-> 3099 ret = ax.plot(*args, **kwargs)
3100 draw_if_interactive()
3101 finally:
[…]
/usr/lib/python3.5/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
221 y = np.atleast_1d(y)
222 if x.shape[0] != y.shape[0]:
--> 223 raise ValueError("x and y must have same first dimension")
224 if x.ndim > 2 or y.ndim > 2:
225 raise ValueError("x and y can be no greater than 2-D")
ValueError: x and y must have same first dimension
plot([1,2,3,4,5,6,7,8,9,10], [1,4,8,2,3,5,8,9,3,6,7])
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-4-ec77aff7bf8c> in <module>() ----> 1 plot([1,2,3,4,5,6,7,8,9,10], [1,4,8,2,3,5,8,9,3,6,7]) /usr/lib/python3.5/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs) 3097 ax.hold(hold) 3098 try: -> 3099 ret = ax.plot(*args, **kwargs) 3100 draw_if_interactive() 3101 finally: /usr/lib/python3.5/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs) 1371 lines = [] 1372 -> 1373 for line in self._get_lines(*args, **kwargs): 1374 self.add_line(line) 1375 lines.append(line) /usr/lib/python3.5/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs) 302 return 303 if len(remaining) <= 3: --> 304 for seg in self._plot_args(remaining, kwargs): 305 yield seg 306 return /usr/lib/python3.5/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs) 280 x = np.arange(y.shape[0], dtype=float) 281 --> 282 x, y = self._xy_from_xy(x, y) 283 284 if self.command == 'plot': /usr/lib/python3.5/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y) 221 y = np.atleast_1d(y) 222 if x.shape[0] != y.shape[0]: --> 223 raise ValueError("x and y must have same first dimension") 224 if x.ndim > 2 or y.ndim > 2: 225 raise ValueError("x and y can be no greater than 2-D") ValueError: x and y must have same first dimension
[I 13:38:34.691 NotebookApp] Kernel started: 26190742-9d29-420f-9f0f-5c8aae026a62Ctrl-CShutdown this notebook server (y/[n])?y then Enteripython notebookEnterThe IPython Notebook is running at: http://localhost:8888/Ctrl-Click if necessary.Untitled.ipynb, and click on it