Example #1
0
def _make_chart_type(chart_type):
    data = pd.DataFrame({
        'x': [28, 55, 43, 91, 81, 53, 19, 87],
        'y': [43, 91, 81, 53, 19, 87, 52, 28],
        'color': list('AAAABBBB'),
    })
    base = alt.Chart(data).mark_point().encode(
        x='x',
        y='y',
        color='color',
    )

    if chart_type in ['layer', 'hconcat', 'vconcat', 'concat']:
        func = getattr(alt, chart_type)
        return func(base.mark_square(), base.mark_circle())
    elif chart_type == 'facet':
        return base.facet('color')
    elif chart_type == 'facet_encoding':
        return base.encode(facet='color')
    elif chart_type == 'repeat':
        return base.encode(alt.X(alt.repeat(),
                                 type='quantitative')).repeat(['x', 'y'])
    elif chart_type == 'chart':
        return base
    else:
        raise ValueError(
            "chart_type='{}' is not recognized".format(chart_type))
Example #2
0
def _make_chart_type(chart_type):
    data = pd.DataFrame({
        "x": [28, 55, 43, 91, 81, 53, 19, 87],
        "y": [43, 91, 81, 53, 19, 87, 52, 28],
        "color": list("AAAABBBB"),
    })
    base = (alt.Chart(data).mark_point().encode(
        x="x",
        y="y",
        color="color",
    ))

    if chart_type in ["layer", "hconcat", "vconcat", "concat"]:
        func = getattr(alt, chart_type)
        return func(base.mark_square(), base.mark_circle())
    elif chart_type == "facet":
        return base.facet("color")
    elif chart_type == "facet_encoding":
        return base.encode(facet="color")
    elif chart_type == "repeat":
        return base.encode(alt.X(alt.repeat(),
                                 type="quantitative")).repeat(["x", "y"])
    elif chart_type == "chart":
        return base
    else:
        raise ValueError(
            "chart_type='{}' is not recognized".format(chart_type))