Exemplo n.º 1
0
def spines_figures():
    """ Generate figures demonstrating functionality of the spines module.
    """
    def new_figure(fac=0.8, maxx=1, miny=-1, maxy=1, margin='all'):
        plt.rcParams['xtick.direction'] = 'out'
        plt.rcParams['ytick.direction'] = 'out'
        fig, axs = plt.subplots(1, 3, figsize=(28, 10))
        if margin == 'lb':
            fig.subplots_adjust(left=7.5,
                                right=1.5,
                                top=0.5,
                                bottom=3.5,
                                wspace=0.4)
        else:
            fig.subplots_adjust(left=7.5,
                                right=7.5,
                                top=3.5,
                                bottom=3.5,
                                wspace=0.4)
        for ax in axs:
            x = np.linspace(0, 1.5, 200)
            y = fac * np.sin(2 * np.pi * 5 * x)
            ax.plot(x, y, lw=2)
            ax.set_xlim(0, maxx)
            ax.set_xticks_delta(0.2)
            ax.set_xlabel('Time [ms]')
            ax.set_ylim(miny, maxy)
            ax.set_yticks_delta(0.5)
            ax.set_ylabel('Voltage [mV]')
        return fig, axs

    def save_fig(fig, name):
        fig.savefig('spines-' + name + '.png')
        plt.close()

    install_figure()

    fig, axs = new_figure()
    axs[0].show_spines('lb')
    axs[1].show_spines('bt')
    axs[2].show_spines('tr')
    save_fig(fig, 'show')

    fig, axs = new_figure(0.8, 1.1, -0.95, 0.95, 'lb')
    axs[0].show_spines('lb')
    axs[0].set_spines_bounds('lb', 'full')
    axs[1].show_spines('lb')
    axs[1].set_spines_bounds('lb', 'data')
    axs[2].show_spines('lb')
    axs[2].set_spines_bounds('lb', 'ticks')
    save_fig(fig, 'bounds')

    fig, axs = new_figure(1.0, 1.0, -1, 1, 'lb')
    axs[0].show_spines('lb')
    axs[0].set_spines_outward('lb', 0)
    axs[1].show_spines('lb')
    axs[1].set_spines_outward('lb', 10)
    axs[2].show_spines('lb')
    axs[2].set_spines_outward('lb', -10)
    save_fig(fig, 'outward')
Exemplo n.º 2
0
def colors_figures():
    """ Generate figures displaying the color palettes.
    """
    install_figure()
    for key, colors in color_palettes.items():
        fig, ax = plt.subplots(figsize=(1 + 2.2 * len(colors), 3))
        fig.subplots_adjust(left=0, right=0, top=0, bottom=0)
        ax.show_spines('')
        rectx = np.array([0.0, 1.0, 1.0, 0.0, 0.0])
        recty = np.array([0.0, 0.0, 1.0, 1.0, 0.0])
        for k, c in enumerate(colors):
            ax.fill(rectx + 1.2 * k, recty, color=colors[c])
            ax.text(0.5 + 1.2 * k, -0.3, c, ha='center')
        ax.set_xlim(-0.1, len(colors) * 1.2 - 0.1)
        ax.set_ylim(-0.4, 1.02)
        fig.savefig('colors-' + key + '.png')
Exemplo n.º 3
0
def darker_figure():
    """ Generate figures demonstrating the darker() function.
    """
    install_figure()
    color = color_palettes['muted']['blue']
    n = 10
    fig, ax = plt.subplots(figsize=(1 + 2.2 * (n + 1), 3))
    fig.subplots_adjust(left=0, right=0, top=0, bottom=0)
    ax.show_spines('')
    rectx = np.array([0.0, 1.0, 1.0, 0.0, 0.0])
    recty = np.array([0.0, 0.0, 1.0, 1.0, 0.0])
    for k in range(n + 1):
        fac = 1.0 - k / float(n)
        ax.fill(rectx + 1.2 * k, recty, color=darker(color, fac))
        ax.text(0.5 + 1.2 * k, -0.3, '%.0f%%' % (100 * fac), ha='center')
    ax.set_xlim(-0.1, (n + 1) * 1.2 - 0.1)
    ax.set_ylim(-0.4, 1.02)
    fig.savefig('colors-darker.png')
Exemplo n.º 4
0
def insets_figures():
    """ Generate figures demonstrating functionality of the insets module.
    """

    def new_figure():
        plt.rcParams['xtick.direction'] = 'out'
        plt.rcParams['ytick.direction'] = 'out'
        fig, ax = plt.subplots(figsize=(12, 8))
        fig.subplots_adjust(left=6.0, right=1.5, top=0.5, bottom=3.0)
        x = np.arange(-2.0, 5.0, 0.01)
        y = np.sin(2.0*np.pi*4.0*x)
        ax.plot(x, y)
        ax.set_xlim(-2.0, 5.0)
        ax.set_xlabel('Time [ms]')
        ax.set_ylim(-1.5, 4.5)
        ax.set_ylabel('Voltage [mV]')
        return fig, ax, x, y

    def label_corners(ax):
        ax.text(0.02, 0.02, '1', ha='left', va='bottom', fontweight='bold', transform=ax.transAxes)
        ax.text(0.98, 0.02, '2', ha='right', va='bottom', fontweight='bold', transform=ax.transAxes)
        ax.text(0.98, 0.98, '3', ha='right', va='top', fontweight='bold', transform=ax.transAxes)
        ax.text(0.02, 0.98, '4', ha='left', va='top', fontweight='bold', transform=ax.transAxes)
        
    def save_fig(fig, name):
        fig.savefig('insets-' + name + '.png')
        plt.close()
        
    install_figure()

    fig, ax, _, _ = new_figure()
    axi = ax.inset((0.2, 0.6, 0.9, 0.95))
    x = np.linspace(0, 1, 50)
    axi.plot(x, x**2, 'r')
    save_fig(fig, 'inset')

    fig, ax, x, y = new_figure()
    axi = ax.zoomed_inset((0.2, 0.6, 0.9, 0.95), (0.0, -1.1, 2.0, 1.1),
                          ((4, 1), (3, 2)), lw=0.5)
    axi.plot(x, y)
    label_corners(axi)
    save_fig(fig, 'zoomed_inset')
Exemplo n.º 5
0
def scalebars_figures():
    """ Generate figure demonstrating functionality of the scalebars module.
    """
    def draw_sine():
        fig, ax = plt.subplots(figsize=(10, 6))
        fig.subplots_adjust(left=0.1, right=3.5, top=0.1, bottom=1.5)
        ax.show_spines('')
        f = 0.5
        x = np.linspace(0.0, 10.0, 200)
        ax.plot(x, np.sin(2.0 * np.pi * f * x), lw=2)
        ax.set_xlim(0.0, 10.0)
        ax.set_ylim(-1.1, 1.1)
        return fig, ax

    def new_figure(w, h):
        fig, ax = plt.subplots(figsize=(w, h))
        fig.subplots_adjust(left=1, right=1, top=1, bottom=1)
        ax.show_spines('')
        ax.set_xlim(0.0, 10.0)
        ax.set_ylim(0.0, 5.0)
        return fig, ax

    def save_fig(fig, name):
        fig.savefig('scalebars-' + name + '.png')
        plt.close()

    def draw_anchor(ax, x, y):
        ax.plot(x, y, '.r', ms=20, transform=ax.transAxes, clip_on=False)

    install_figure()
    scalebar_params(format_large='%.0f',
                    format_small='%.1f',
                    lw=3,
                    capsize=0,
                    clw=0.5)

    fig, ax = draw_sine()
    ax.scalebars(1.05, 0.0, 2, 1, 's', 'mV', ha='right', va='bottom')
    save_fig(fig, 'scalebars')

    fig, ax = draw_sine()
    ax.xscalebar(1.0, 0.0, 2, 's', ha='right', va='bottom')
    save_fig(fig, 'xscalebar')

    fig, ax = draw_sine()
    ax.yscalebar(1.05, 0.0, 1, 'mV', ha='right', va='bottom')
    save_fig(fig, 'yscalebar')

    fig, ax = new_figure(10, 3)
    ax.xscalebar(0.0, 0.8, 2, 'mm', ha='left', va='bottom', lw=3)
    ax.xscalebar(0.0, 0.3, 2, 'mm', ha='left', va='bottom', lw=6)
    ax.xscalebar(1.0,
                 0.8,
                 2,
                 'mm',
                 ha='right',
                 va='bottom',
                 lw=4,
                 capsize=4,
                 clw=2)
    ax.xscalebar(1.0,
                 0.3,
                 2,
                 'mm',
                 ha='right',
                 va='bottom',
                 lw=4,
                 capsize=6,
                 clw=1)
    save_fig(fig, 'styles')

    fig, ax = new_figure(10, 3)
    draw_anchor(ax, 0.0, 0.8)
    ax.xscalebar(0.0, 0.8, 2, 's', ha='left', va='top', lw=4)
    draw_anchor(ax, 0.5, 0.8)
    ax.xscalebar(0.5, 0.8, 2, 's', ha='center', va='top', lw=4)
    draw_anchor(ax, 1.0, 0.8)
    ax.xscalebar(1.0, 0.8, 2, 's', ha='right', va='top', lw=4)
    draw_anchor(ax, 0.0, 0.3)
    ax.xscalebar(0.0, 0.3, 2, 's', ha='left', va='bottom', lw=4)
    draw_anchor(ax, 0.5, 0.3)
    ax.xscalebar(0.5, 0.3, 2, 's', ha='center', va='bottom', lw=4)
    draw_anchor(ax, 1.0, 0.3)
    ax.xscalebar(1.0, 0.3, 2, 's', ha='right', va='bottom', lw=4)
    save_fig(fig, 'xpos')

    fig, ax = new_figure(5, 8)
    draw_anchor(ax, 0.3, 1.0)
    ax.yscalebar(0.3, 1.0, 1, 'mV', ha='left', va='top', lw=4)
    draw_anchor(ax, 0.3, 0.5)
    ax.yscalebar(0.3, 0.5, 1, 'mV', ha='left', va='center', lw=4)
    draw_anchor(ax, 0.3, 0.0)
    ax.yscalebar(0.3, 0.0, 1, 'mV', ha='left', va='bottom', lw=4)
    draw_anchor(ax, 0.7, 1.0)
    ax.yscalebar(0.7, 1.0, 1, 'mV', ha='right', va='top', lw=4)
    draw_anchor(ax, 0.7, 0.5)
    ax.yscalebar(0.7, 0.5, 1, 'mV', ha='right', va='center', lw=4)
    draw_anchor(ax, 0.7, 0.0)
    ax.yscalebar(0.7, 0.0, 1, 'mV', ha='right', va='bottom', lw=4)
    save_fig(fig, 'ypos')

    fig, ax = new_figure(10, 7)
    draw_anchor(ax, 0.2, 0.8)
    ax.scalebars(0.2, 0.8, 2, 1, 's', 'mV', ha='left', va='top')
    draw_anchor(ax, 0.8, 0.8)
    ax.scalebars(0.8, 0.8, 2, 1, 's', 'mV', ha='right', va='top')
    draw_anchor(ax, 0.2, 0.1)
    ax.scalebars(0.2, 0.1, 2, 1, 's', 'mV', ha='left', va='bottom')
    draw_anchor(ax, 0.8, 0.1)
    ax.scalebars(0.8, 0.1, 2, 1, 's', 'mV', ha='right', va='bottom')
    save_fig(fig, 'pos')
Exemplo n.º 6
0
def ticks_figures():
    """ Generate figure demonstrating functionality of the ticks module.
    """
    def new_figure():
        plt.rcParams['xtick.direction'] = 'out'
        fig, ax = plt.subplots(figsize=(10, 1.2))
        fig.subplots_adjust(left=2, right=2, top=0, bottom=2.5)
        ax.set_ylim(0, 1)
        ax.show_spines('b')
        return fig, ax

    def save_fig(fig, name):
        fig.savefig('ticks-' + name + '.png')
        plt.close()

    install_figure()

    fig, ax = new_figure()
    ax.set_xticks_delta(0.5)
    save_fig(fig, 'delta')

    fig, ax = new_figure()
    ax.set_xticks_format('%04.1f')
    save_fig(fig, 'format')

    fig, ax = new_figure()
    ax.set_xticks_fixed((0, 0.3, 1))
    save_fig(fig, 'fixed')

    fig, ax = new_figure()
    ax.set_xticks_fixed((0, 0.5, 1), ('a', 'b', 'c'))
    save_fig(fig, 'fixedlabels')

    fig, ax = new_figure()
    ax.set_xscale('log')
    ax.set_xlim(1e-6, 1e0)
    ax.set_xticks_prefix()
    save_fig(fig, 'prefix')

    fig, ax = new_figure()
    ax.set_xlim(-1, 1)
    ax.set_xticks_fracs(4)
    save_fig(fig, 'fracs')

    fig, ax = new_figure()
    ax.set_xlim(-np.pi, 2 * np.pi)
    ax.set_xticks_pifracs(2)
    save_fig(fig, 'pifracs')

    fig, ax = new_figure()
    ax.set_xlim(0, 4 * np.pi / 3)
    ax.set_xticks_pifracs(3, True)
    save_fig(fig, 'pifracstop')

    fig, ax = new_figure()
    ax.set_xticks_blank()
    save_fig(fig, 'blank')

    fig, ax = new_figure()
    ax.set_xticks_off()
    save_fig(fig, 'off')