コード例 #1
0
ファイル: test_api.py プロジェクト: bamishr/Python_Learning
    # override default types
    chart = (alt.Chart(data).mark_point().encode(alt.X("x", type="nominal"),
                                                 alt.Y("y", type="ordinal")))
    dct = chart.to_dict()
    assert dct["encoding"]["x"]["type"] == "nominal"
    assert dct["encoding"]["y"]["type"] == "ordinal"


@pytest.mark.parametrize(
    "args, kwargs",
    [
        getargs(detail=["value:Q", "name:N"], tooltip=["value:Q", "name:N"]),
        getargs(detail=["value", "name"], tooltip=["value", "name"]),
        getargs(alt.Detail(["value:Q", "name:N"]),
                alt.Tooltip(["value:Q", "name:N"])),
        getargs(alt.Detail(["value", "name"]), alt.Tooltip(["value", "name"])),
        getargs(
            [alt.Detail("value:Q"),
             alt.Detail("name:N")],
            [alt.Tooltip("value:Q"),
             alt.Tooltip("name:N")],
        ),
        getargs(
            [alt.Detail("value"), alt.Detail("name")],
            [alt.Tooltip("value"), alt.Tooltip("name")],
        ),
    ],
)
def test_multiple_encodings(args, kwargs):
    df = pd.DataFrame({"value": [1, 2, 3], "name": ["A", "B", "C"]})
コード例 #2
0
    chart = alt.Chart(data).mark_point().encode(alt.X('x'), alt.Y('y'),
                                                alt.Color('c'))
    _check_encodings(chart)

    # override default types
    chart = alt.Chart(data).mark_point().encode(alt.X('x', type='nominal'),
                                                alt.Y('y', type='ordinal'))
    dct = chart.to_dict()
    assert dct['encoding']['x']['type'] == 'nominal'
    assert dct['encoding']['y']['type'] == 'ordinal'


@pytest.mark.parametrize('args, kwargs', [
    getargs(detail=['value:Q', 'name:N'], tooltip=['value:Q', 'name:N']),
    getargs(detail=['value', 'name'], tooltip=['value', 'name']),
    getargs(alt.Detail(['value:Q', 'name:N']), alt.Tooltip(['value:Q', 'name:N'])),
    getargs(alt.Detail(['value', 'name']), alt.Tooltip(['value', 'name'])),
    getargs([alt.Detail('value:Q'), alt.Detail('name:N')],
            [alt.Tooltip('value:Q'), alt.Tooltip('name:N')]),
    getargs([alt.Detail('value'), alt.Detail('name')],
            [alt.Tooltip('value'), alt.Tooltip('name')]),
])
def test_multiple_encodings(args, kwargs):
    df = pd.DataFrame({
        'value': [1, 2, 3],
        'name': ['A', 'B', 'C'],
    })
    encoding_dct = [{'field': 'value', 'type': 'quantitative'},
                    {'field': 'name', 'type': 'nominal'}]
    chart = alt.Chart(df).mark_point().encode(*args, **kwargs)
    dct = chart.to_dict()