예제 #1
0
def test_plot():
    """Test line object with no extra arguments"""
    x, t, X, T, s = set_line_plot_data()
    line_obj = anim.plot(x, s)[0]
    standard_line_tests(line_obj)
    assert_array_equal(np.arange(line_obj.t_len), line_obj.titles)
    assert line_obj.xlim == (X.min(), X.max())
    assert line_obj.ylim == (s.min(), s.max())
    assert line_obj.kwargs == {}
    assert list(line_obj.axkwargs) == ['xlim', 'ylim']
    assert line_obj.axkwargs['xlim'] == line_obj.xlim
    assert line_obj.axkwargs['ylim'] == line_obj.ylim
예제 #2
0
def test_create_line_object_titles():
    """Test line object with specified titles"""
    x, t, X, T, s = set_line_plot_data()
    titles = ['data at time {}'.format(i) for i in np.arange(len(t))]
    line_obj = anim.plot(x, s, titles=titles)[0]
    standard_line_tests(line_obj)
    assert titles == line_obj.titles
    assert line_obj.xlim == (X.min(), X.max())
    assert line_obj.ylim == (s.min(), s.max())
    assert line_obj.kwargs == {}
    assert list(line_obj.axkwargs) == ['xlim', 'ylim']
    assert line_obj.axkwargs['xlim'] == line_obj.xlim
    assert line_obj.axkwargs['ylim'] == line_obj.ylim
예제 #3
0
def test_create_line_object_axkwargs():
    """Test line object with axis limit arguments"""
    xlim = [1, 3]
    ylim = [-2, 2]
    xlabel = 'x'
    ylabel = 'data'
    x, t, X, T, s = set_line_plot_data()
    axkwargs = {
        'xlim': tuple(xlim),
        'ylim': tuple(ylim),
        'xlabel': xlabel,
        'ylabel': ylabel
    }
    line_obj = anim.plot(x, s, axkwargs=axkwargs)[0]
    standard_line_tests(line_obj)
    assert_array_equal(np.arange(line_obj.t_len), line_obj.titles)
    assert line_obj.xlim == tuple(xlim)
    assert line_obj.ylim == tuple(ylim)
    assert line_obj.kwargs == {}
    assert list(line_obj.axkwargs) == ['xlim', 'ylim', 'xlabel', 'ylabel']
# line field to be plotted in subplot 2 - propagating sine wave
meridional_mean = np.mean(cos_wave, axis=0)

# Create titles for each subplot
quad_titles = ['Wave at time {:.02f}'.format(i) for i in t]
line_titles = ['Meridional mean at time {:.02f}'.format(i) for i in t]

# Create axis keyword arguments
quad_axkwargs = {'xlabel': 'x', 'ylabel': 'y'}
line_axkwargs = {'xlabel': 'x', 'ylabel': 'Merid. Mean'}

# Create the animation objects
cos_quad = anim.pcolormesh(x,
                           y,
                           cos_wave,
                           clims=[-2, 2],
                           titles=quad_titles,
                           axkwargs=quad_axkwargs,
                           cb_label='Energy')

mean_line = anim.plot(Y[:, 0, :],
                      meridional_mean,
                      'r',
                      titles=line_titles,
                      axkwargs=line_axkwargs)

# Concatenate the objects to create 2 subplots in a row
anim_list = cos_quad + mean_line

# Animate the objects
anim.animate(anim_list, figsize=(10, 7))  #,anim_save='quad_line.mp4')
예제 #5
0
import mpl_animation.anim as anim
import numpy as np

# x-axis of plot
x = np.arange(0, 2 * np.pi, 1e-1)
# time-axis of plot
t = np.arange(0, 8 * np.pi, 1e-1)

# Use meshgrid to help create the data to be plotted - but
# can also give 1D coordinate arrays to create_line_object
T, X = np.meshgrid(t, x)
# field to be plotted in subplot 1 - propagating cosine wave
cos_wave = (t / t.max()) * np.cos(X - T)
# field to be plotted in subplot 2 - propagating sin wave
sin_wave = (t / t.max()) * np.sin(X - T)

# Create a title
titles = ['Wave at time {:.02f}'.format(i) for i in t]
# Create the animation objects
cos_line = anim.plot(x, cos_wave, titles=titles)
sin_line = anim.plot(x, sin_wave, 'r', titles=titles)

# Concatenate the objects
anim_list = cos_line + sin_line

# Animate the objects
anim.animate(anim_list, figsize=(10, 7))  #,anim_save='line.mp4', )