Evolution is progress—
progress is creativity.

# Creole Plot Macro

The creole plot macro translates the body of the macro into a code fragment, that is executed to create the picture.

## Usage

<<mathplot title="Image Title" show_source=True>>
def set_figure(fig):
<</mathplot>>


## Examples

def set_figure(fig):
ax.set_xlabel("My X-label")
ax.set_ylabel("My Y-label")
title = u"My first still empty plot"
ax.set_title(title)


The following example is copied from here.

def set_figure(fig):
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
ax1.set_ylabel('exp')

ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin')


The following example is copied from here.

def set_figure(fig):
import numpy as np
N = 5
menMeans   = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd     = (2, 3, 4, 1, 2)
womenStd   = (3, 5, 2, 3, 3)
ind = np.arange(N)    # the x locations for the groups
width = 0.35       # the width of the bars: can also be len(x) sequence

p1 = ax1.bar(ind, menMeans,   width, color='r', yerr=womenStd)
p2 = ax1.bar(ind, womenMeans, width, color='y', bottom=menMeans, yerr=menStd)

ax1.set_ylabel('Scores')
ax1.set_title('Scores by group and gender')
ax1.set_xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') )
ax1.set_yticks(np.arange(0,81,10))
ax1.legend( (p1[0], p2[0]), ('Men', 'Women') )


The website http://matplotlib.sourceforge.net/api/axes_api.html#module-matplotlib.axes provides a whole collection of additional examples.

def set_figure(fig):
import numpy as np
import matplotlib.mlab as mlab

mu, sigma = 100, 15
x = mu + sigma*np.random.randn(10000)

# the histogram of the data
n, bins, patches = ax1.hist(x, 50, normed=1, facecolor='green', alpha=0.75)

# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)

l = ax1.plot(bins, y, 'r--', linewidth=1)

ax1.set_xlabel('Smarts')
ax1.set_ylabel('Probability')
ax1.set_title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
ax1.axis([40, 160, 0, 0.03])
ax1.grid(True)


Tags: Software

(c) Mato Nagel, Weißwasser 2004-2013, Disclaimer