Org Mode Python Plotting and Return values

Testing out some python code blocks in org babel. See http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html

import matplotlib, numpy
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(4,2))
x=numpy.linspace(-15,15)
plt.plot(numpy.sin(x)/x)
fig.tight_layout()
plt.savefig('python-matplot-fig.png')
return 'python-matplot-fig.png' # return filename to org-mode
Sample plot

Sample plot

def foo(x):
    bar=[1,2,3]
    baz=42
    qux=[[1,2,3],[4,5,6]]

    if x>0:
        return bar

    else:
        return qux

return foo(-5)
1 2 3
4 5 6
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s