Example #1
0
 def test_line(self):
     chart = alt.Chart(df_line).mark_line().encode(
         alt.X('a'),
         alt.Y('b'),
     )
     fig, _ = convert(chart)
     return fig
Example #2
0
def test_axis_scale_NotImplemented_quantitative(df, x, type):
    chart = alt.Chart(df).mark_point().encode(
        alt.X(x, scale=alt.Scale(type=type)), alt.Y('a'))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
Example #3
0
def test_scatter_temporal(channel):
    chart = alt.Chart(df).mark_point().encode(alt.X("years"), channel)
    mapping = convert(chart)
    mapping['y'] = df['quantitative'].values
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    return fig
Example #4
0
def test_axis_scale_type_y_quantitative(column, type, base, exponent):
    chart = alt.Chart(df_quant).mark_point().encode(
        alt.X('a'),
        alt.Y(column, scale=alt.Scale(type=type, base=base,
                                      exponent=exponent)))
    fig, ax = convert(chart)
    plt.show()
    return fig
Example #5
0
def test_axis(df, x, y):
    chart = alt.Chart(df).mark_point().encode(alt.X(x), alt.Y(y))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #6
0
def test_axis_formatter_fail():
    chart = alt.Chart(df_quant).mark_point().encode(
        alt.X('c', axis=alt.Axis(format='-$.2g')),
        alt.Y('b', axis=alt.Axis(format='+.3r')))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
Example #7
0
def test_axis_formatter_temporal():
    """Note: this test is separate from the other test_axis_formatter test because the parametrization created issues
    with the filename for the image comparison test."""
    chart = alt.Chart(df_temp).mark_point().encode(
        alt.X('months:T', axis=alt.Axis(format='%b %Y')),
        alt.Y('hrs:T', axis=alt.Axis(format='%H:%M:%S')))
    fig, ax = convert(chart)
    return fig
Example #8
0
def test_quantitative_x_count_y():
    df_count = pd.DataFrame({
        "a": [1, 1, 2, 3, 5],
        "b": [1.4, 1.4, 2.9, 3.18, 5.3]
    })
    chart = alt.Chart(df_count).mark_point().encode(alt.X('a'),
                                                    alt.Y('count()'))
    mapping = convert(chart)
Example #9
0
def test_axis_scale_basic(df, column, scale_type):
    chart = alt.Chart(df).mark_point().encode(
        alt.X(column, scale=alt.Scale(type=scale_type)), alt.Y('a'))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #10
0
def test_axis_unaggregated_quantitative():
    chart = alt.Chart(df_quant).mark_point().encode(
        alt.X('a', scale=alt.Scale(domain="unaggregated")),
        alt.Y('c', scale=alt.Scale(domain="unaggregated")))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    plt.close()
    convert_axis(ax, chart)
Example #11
0
def test_axis_more_than_x_and_y():
    chart = alt.Chart(df_quant).mark_point().encode(alt.X('a'),
                                                    alt.Y('b'),
                                                    color=alt.Color('c'))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #12
0
def test_axis_formatter(df, x, y, format_x, format_y):
    chart = alt.Chart(df).mark_point().encode(
        alt.X(x, axis=alt.Axis(format=format_x)),
        alt.Y(y, axis=alt.Axis(format=format_y)))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #13
0
def test_axis_scale_type_x_quantitative(column, type, base, exponent):
    chart = alt.Chart(df_quant).mark_point().encode(
        alt.X(column, scale=alt.Scale(type=type, base=base,
                                      exponent=exponent)), alt.Y('a'))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #14
0
def test_axis_tickCount(df, x, tickCount):
    chart = alt.Chart(df).mark_point().encode(
        alt.X(x, axis=alt.Axis(tickCount=tickCount)),
        alt.Y('a', axis=alt.Axis(tickCount=tickCount)))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #15
0
def test_axis_values(df, y, vals):
    chart = alt.Chart(df).mark_point().encode(
        alt.X('a', axis=alt.Axis(values=[-1, 1, 1.5, 2.125, 3])),
        alt.Y(y, axis=alt.Axis(values=vals)))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #16
0
def test_axis_domain(df, x, y, x_dom, y_dom):
    chart = alt.Chart(df).mark_point().encode(
        alt.X(x, scale=alt.Scale(domain=x_dom)),
        alt.Y(y, scale=alt.Scale(domain=y_dom)))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #17
0
def test_axis_zero_quantitative(x, y, zero):
    chart = alt.Chart(df_quant).mark_point().encode(
        alt.X(x, scale=alt.Scale(zero=zero)),
        alt.Y(y, scale=alt.Scale(zero=zero)))
    mapping = convert(chart)
    fig, ax = plt.subplots()
    ax.scatter(**mapping)
    convert_axis(ax, chart)
    fig.tight_layout()
    return fig
Example #18
0
def test_convert_y_success_temporal(column):
    chart = alt.Chart(df).mark_point().encode(alt.Y(column))
    mapping = convert(chart)
    assert list(mapping['y']) == list(mdates.date2num(df[column].values))
Example #19
0
def test_convert_y_fail():
    chart_spec = alt.Chart(df).encode(y='b:N').mark_point()
    with pytest.raises(KeyError):
        convert(chart_spec)
Example #20
0
def test_invalid_temporal():
    chart = alt.Chart(df).mark_point().encode(alt.X('quant:T'))
    convert(chart)
Example #21
0
def test_convert_y_success(channel):
    chart_spec = alt.Chart(df).encode(y=channel).mark_point()
    mapping = convert(chart_spec)
    assert list(mapping['y']) == list(df[channel].values)
Example #22
0
def test_encoding_not_provided():
    chart_spec = alt.Chart(df).mark_point()
    with pytest.raises(ValueError):
        convert(chart_spec)
Example #23
0
def test_invalid_encodings():
    chart_spec = alt.Chart(df).encode(x2='quant').mark_point()
    with pytest.raises(ValueError):
        convert(chart_spec)
Example #24
0
def test_quantitative_scatter(chart):
    mapping = convert(chart)
    plt.scatter(**mapping)
    plt.show()
Example #25
0
def test_scatter_temporal(channel):
    chart = alt.Chart(df).mark_point().encode(alt.X("years"), channel)
    mapping = convert(chart)
    mapping['y'] = df['quantitative'].values
    plt.scatter(**mapping)
    plt.show()
Example #26
0
def test_timeUnit():
    chart = alt.Chart(df).mark_point().encode(alt.X('date(combination)'))
    convert(chart)
Example #27
0
def test_convert_size_success(channel, type):
    chart_spec = alt.Chart(df).encode(
        size='{}:{}'.format(channel, type)).mark_point()
    mapping = convert(chart_spec)
    assert list(mapping['s']) == list(df[channel].values)
Example #28
0
def test_convert_stroke_fail_temporal(column):
    chart = alt.Chart(df).mark_point().encode(alt.Stroke(column))
    convert(chart)
Example #29
0
def test_quantitative_stroke():
    chart = alt.Chart(df_quant).mark_point().encode(alt.Stroke('fill'))
    convert(chart)
Example #30
0
def test_convert_size_success_nominal():
    chart_spec = alt.Chart(df).encode(size='nom').mark_point()
    with pytest.raises(NotImplementedError):
        convert(chart_spec)