logo4 Evolution is progress—                          
progress is creativity.        

Creole Plot Macro

view wiki view wiki view wiki view wiki

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


<<mathplot title="Image Title" show_source=True>>
def set_figure(fig):    
# add some functions


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

The following example is copied from here.

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

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

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

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
    ax1 = fig.add_subplot(111)
    p1 = ax1.bar(ind, menMeans,   width, color='r', yerr=womenStd)
    p2 = ax1.bar(ind, womenMeans, width, color='y', bottom=menMeans, yerr=menStd)
    ax1.set_title('Scores by group and gender')
    ax1.set_xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') )
    ax1.legend( (p1[0], p2[0]), ('Men', 'Women') )
Bar chart

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
    ax1 = fig.add_subplot(111)
    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_title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
    ax1.axis([40, 160, 0, 0.03])
Bar chart

Tags: Software


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