Exemplo n.º 1
0
def test_plot_pandas_default(data):

    default_kw = {'xlabel': data['xlabel'], 'ylabel': data['ylabel']}
    desired_fig = Figure()
    desired_ax = desired_fig.subplots(subplot_kw=default_kw)
    desired_ax.plot(data['xdata'], data['ydata'])

    actual_fig, actual_ax = default_plotter(data['data'])
    assert_figures_equal(actual_fig, desired_fig)
Exemplo n.º 2
0
def test_plot_pandas_log(data):
    desired_fig = Figure()
    log_kw= {
        'xlabel': data['xlabel'], 'ylabel': data['ylabel'],
        'xscale': 'log', 'yscale': 'log'}

    desired_ax = desired_fig.subplots(subplot_kw=log_kw)
    desired_ax.plot(data['xdata'], data['ydata'])
    actual_fig, actual_ax = default_plotter(data['data'],
            subplot_kw=log_kw)
    assert_figures_equal(actual_fig, desired_fig)
Exemplo n.º 3
0
def test_plot_pandas_twinx(data):
    """
    Tests that we can generate a plot with multiple axes when we pass in different y-valued data.
    """
    second_data = data['data'].copy()
    second_data['Frequency (Hz)'] *= 2
    second_data.rename(columns={'Frequency (Hz)': 'Frequency (kHz)'},
            inplace=True)

    default_kw = {'xlabel': data['xlabel'], 'ylabel': data['ylabel']}
    desired_fig = Figure()
    desired_ax = desired_fig.subplots(subplot_kw=default_kw)
    desired_ax.plot(data['xdata'], data['ydata'])
    new_ax = desired_ax.twinx()
    new_ax.plot(second_data['Time (ms)'], second_data['Frequency (kHz)'])
    new_ax.set_xlabel('Time (ms)')
    new_ax.set_ylabel('Frequency (kHz)')

    actual_fig, ax = default_plotter(data['data'])
    actual_fig, _ = default_plotter(second_data, fig=actual_fig)
    assert_figures_equal(actual_fig, desired_fig)
Exemplo n.º 4
0
def test_plot_linear_fit(impedance_data_complex):
    x_data  = np.array([0, 1, 2, 3, 4, 5])
    y_data = np.array([0, 1, 2, 3, 4, 5])
    def linear_fit(x, offset, slope):
        return offset + x * slope

    fig_actual, ax_actual = default_plotter(
            x_data, y_data,
            fit_func=linear_fit)

    fig_desired = Figure()
    ax_desired = fig_desired.subplots()
    ax_desired.plot(x_data, y_data)
    ax_desired.plot(x_data, y_data, linestyle='dashed')
    assert_figures_equal(fig_actual, fig_desired,
            rtol=1e-8, atol=1e-8)
Exemplo n.º 5
0
def test_plot_pandas_theory(data):
    def gaussian(x, a=1, mu=0, sigma=1):
        return a*np.exp(-np.square((x - mu)/(np.sqrt(2)*sigma)))

    subplot_kw= {'xlabel': data['xlabel'], 'ylabel': data['ylabel']}
    line_kw = {'linestyle': 'dashed'}
    theory_kw = {'a': 2, 'mu': 1, 'sigma': 3}
    theory_data = gaussian(data['xdata'], a=2, mu=1, sigma=3)

    desired_fig = Figure()
    desired_ax = desired_fig.subplots(subplot_kw=subplot_kw)
    desired_ax.plot(data['xdata'], data['ydata'])
    desired_ax.plot(data['xdata'], theory_data, **line_kw)
    actual_fig, actual_ax = default_plotter(data['data'],
        theory_func=gaussian, theory_kw=theory_kw)
    assert_figures_equal(actual_fig, desired_fig)
Exemplo n.º 6
0
def test_plot_pandas_theory_data(data):
    default_kw = {'xlabel': data['xlabel'], 'ylabel': data['ylabel']}
    desired_fig = Figure()
    desired_ax = desired_fig.subplots(subplot_kw=default_kw)
    theory_line_kw = {'linestyle': 'dashed'}
    theory_data=pd.DataFrame({
            data['xlabel']: [0, 1, 2, 3],
            data['ylabel']: [2, 3, 4, 5],
            })

    desired_ax.plot(data['xdata'], data['ydata'])
    desired_ax.plot(theory_data[data['xlabel']],
            theory_data[data['ylabel']], **theory_line_kw)
    desired_ax.set_xlim(0.9, 3.3)

    actual_fig, actual_ax = default_plotter(data['data'],
            theory_data=theory_data)
    assert_figures_equal(actual_fig, desired_fig)