# makes sure inline plotting is enabled %pylab --no-import-all inline #loads a customer marplotlib configuration file def CustomPlot(): import json s = json.load( open("static/matplotlibrc.json") ) matplotlib.rcParams.update(s) figsize(18, 6) from IPython.core.display import HTML def css_styling(): styles = open("static/custom.css", "r").read() return HTML(styles) css_styling() # press shift-enter to run code print "Hallo Pycon" #IPython -- An enhanced Interactive Python - Quick Reference Card %quickref # now press shift-ender # lets degine a function with a long name. def long_silly_dummy_name(a, b): """ This is the docstring for dummy. It takes two arguments a and b It returns the sum of a and b No error checking is done! """ return a+b # lets get the docstring or some help long_silly_dummy_name? long_silly_dummy_name?? #press tab to autocplete long_si # press shift-enter to run long_silly_dummy_name(5,6) %%timeit x = 0 # setup for i in range(100000): #lets use range here x = x + i**2 %%timeit x = 0 # setup for i in xrange(100000): #replace range with slightly improved xrange x += i**2 from IPython.display import HTML raw = raw_input("enter your input here >>> ") print "Hallo, ",raw from IPython.display import FileLink, FileLinks FileLinks('.', notebook_display_formatter=True) filelist = !ls #read the current directory into variable for x,i in enumerate(filelist): print '#',x, '--->', i from IPython.display import Image Image('static/python-vs-java.jpg') from IPython.display import YouTubeVideo YouTubeVideo('iwVvqwLDsJo', width=200, height=200) from matplotlib.pylab import xkcd #xkcd() CustomPlot() from numpy import * #generate some data n = array([0,1,2,3,4,5]) xx = np.linspace(-0.75, 1., 100) x = linspace(0, 5, 10) y = x ** 2 fig, axes = plt.subplots(1, 4, figsize=(12,3)) axes[0].scatter(xx, xx + 0.25*randn(len(xx))) axes[0].set_title('scatter') axes[1].step(n, n**2, lw=2) axes[1].set_title('step') axes[2].bar(n, n**2, align="center", width=0.5, alpha=0.5) axes[2].set_title('bar') axes[3].fill_between(x, x**2, x**3, color="green", alpha=0.5); axes[3].set_title('fill') for i in range(4): axes[i].set_xlabel('x') axes[0].set_ylabel('y') show() CustomPlot() font_size = 20 figsize(11.5, 6) fig, ax = plt.subplots() ax.plot(xx, xx**2, xx, xx**3) ax.set_title(r"Combined Plot $y=x^2$ vs. $y=x^3$", fontsize = font_size) ax.set_xlabel(r'$x$', fontsize = font_size) ax.set_ylabel(r'$y$', fontsize = font_size) fig.tight_layout() # inset inset_ax = fig.add_axes([0.29, 0.45, 0.35, 0.35]) # X, Y, width, height inset_ax.plot(xx, xx**2, xx, xx**3) inset_ax.set_title(r'zoom $x=0$',fontsize=font_size) # set axis range inset_ax.set_xlim(-.2, .2) inset_ax.set_ylim(-.005, .01) # set axis tick locations inset_ax.set_yticks([0, 0.005, 0.01]) inset_ax.set_xticks([-0.1,0,.1]); show() CustomPlot() figsize(11.5, 6) font_size = 20 fig, ax = plt.subplots() ax.plot(xx, xx**2, xx, xx**3) ax.set_xlabel(r'$x$', fontsize = font_size) ax.set_ylabel(r'$y$', fontsize = font_size) ax.set_title(r"Adding Text $y=x^2$ vs. $y=x^3$", fontsize = font_size) ax.text(0.15, 0.2, r"$y=x^2$", fontsize=font_size, color="blue") ax.text(0.65, 0.1, r"$y=x^3$", fontsize=font_size, color="green"); from matplotlib import pyplot as plt import numpy as np plt.xkcd() fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') plt.xticks([]) plt.yticks([]) ax.set_ylim([-30, 10]) data = np.ones(100) data[70:] -= np.arange(30) plt.annotate( 'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED', xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10)) plt.plot(data) plt.xlabel('time') plt.ylabel('my overall health') fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.bar([-0.125, 1.0-0.125], [0, 100], 0.25) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.set_xticks([0, 1]) ax.set_xlim([-0.5, 1.5]) ax.set_ylim([0, 110]) ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT']) plt.yticks([]) plt.title("CLAIMS OF SUPERNATURAL POWERS") plt.show() from sympy import * init_printing(use_latex=True) x = Symbol('x') y = Symbol('y') series(exp(x), x, 1, 5) eq = ((x+y)**2 * (x+1)) eq expand(eq) a = 1/x + (x*sin(x) - 1)/x a simplify(a) from pandas import DataFrame, read_csv Cape_Weather = DataFrame( read_csv('data/CapeTown_2009_Temperatures.csv' )) Cape_Weather.head() CustomPlot() figsize(11.5, 6) font_size = 20 title('Cape Town temparature(2009)',fontsize = font_size) xlabel('Day number',fontsize = font_size) ylabel(r'Temperature [$^\circ C$] ',fontsize = font_size) Cape_Weather.high.plot() Cape_Weather.low.plot() show() CustomPlot() figsize(11.5, 6) font_size = 20 title( 'Mean solar radiation(horisontal plane)', fontsize=font_size) xlabel('Month Number', fontsize = font_size) ylabel(r'$MJ / day / m^2$',fontsize = font_size) Cape_Weather.radiation.plot() show() # lets look at a proxy for heating degree and cooling degree days level = 25 print Cape_Weather[ Cape_Weather['high'] > level ].count() print Cape_Weather[ Cape_Weather['high'] <= level ].count() # Basic descriptive statistics print Cape_Weather['high'].describe() CustomPlot() figsize(11.5, 6) font_size = 20 title('Cape Town temperature distribution', fontsize=font_size) ylabel('Day count',fontsize = font_size) xlabel(r'Temperature [$^\circ C $] ',fontsize = font_size) Cape_Weather['high'].hist(bins=6) show() from IPython.display import Math Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx') from IPython.display import Latex Latex(r"""\begin{eqnarray} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{eqnarray}""") %pdb on foo = 1 bar = 'a' print foo+bar %load http://pastebin.com/raw.php?i=mGiV1FwY CustomPlot() font_size = 20 figsize(11.5, 6) t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) plot(t, s) xlabel(r'time $(s)$', fontsize=font_size) ylabel('voltage $(mV)$', fontsize=font_size) title('Voltage', fontsize=font_size) grid(True) from IPython.display import HTML input_form = """
Variable Name:
Variable Value:
""" javascript = """ """ HTML(input_form + javascript) qwerty %pastebin "cell one" 0-10 %connect_info !ipython builddocs.ipy; print "Done" FileLinks('output/')