Plotting with Matplotlib

Matplotlib can be imported and images can be saved as an SVG.

Example Code

import io
np = imports['numpy']
plt = imports['matplotlib'].pyplot

def add_form_default_values():
    fig = plt.figure(figsize = [7,5])
    plt.title('This is the Initial Graph, See what happens after clicking submit button below')
    plt.xlabel('t')
    plt.ylabel('y')
    plt.plot([1,2,3,4], [1,2,3,4], '--x')
    plt.grid(b=True)
    imgdata = io.StringIO()
    fig.savefig(imgdata, format='svg')
    return {'an_interesting_svg': {'action': 'update', 'value': imgdata.getvalue()}}


def main(form_data):
    fig = plt.figure(figsize = [7,5])
    plt.title('After clicking submit button')
    plt.xlabel('t')
    plt.ylabel('y')
    plt.plot(range(15), range(15), '--rx')
    plt.grid(b=True)
    imgdata = io.StringIO()
    fig.savefig(imgdata, format='svg')
    return {'an_interesting_svg': {'action': 'update', 'value': imgdata.getvalue()}}

def main_2(form_data):
    fig = plt.figure(figsize = [7,5])
    plt.title('Thank you for clicking on submit 2')
    plt.xlabel('t')
    plt.ylabel('y')
    plt.plot(range(10), range(10), '--gx')
    plt.plot(range(10), np.exp(np.arange(10)) * 1e-2, '--kx')
    plt.grid(b=True)
    imgdata = io.StringIO()
    fig.savefig(imgdata, format='svg')
    return {'an_interesting_svg': {'action': 'update', 'value': imgdata.getvalue()}}

Example Form Design

The form design to go along with the code is: Screenshot

Rendered Result

Screenshot