How to use the altair.layer function in altair

To help you get started, we’ve selected a few altair examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neptune-ml / neptune-lib / neptunelib / contrib / viz / experiments.py View on Github external
highlight_bottom = base_bottom.encode(
                    color=alt.value('darkblue'),
                ).transform_filter(
                interval
            )

    best_score = alt.Chart(data).mark_rule().encode(
                    x=alt.X(alt.repeat('column'), aggregate='mean',type='quantitative', axis=None),
                    color=alt.value('firebrick'),
                    size=alt.SizeValue(3),
                ).transform_filter(
                interval
            )
    #TODO get best score not mock https://altair-viz.github.io/user_guide/transform.html
    
    bottom_charts = alt.layer(
        base_bottom,
        highlight_bottom,
        best_score,
        data=data
        ).repeat(
            column=param_cols,
        )
    
    metric_line = alt.Chart(data, width=width).mark_area(filled=False).encode(
            y=alt.Y("{}:Q".format(metric_col),bin=alt.Bin(maxbins=metric_bins), title=None),
            x=alt.X('count()', title=metric_col),
            color=alt.Color('mean({}):Q'.format(metric_col), scale=alt.Scale(scheme='yelloworangered'), legend=None),
            ).add_selection(
                interval
            )
    metric_bar = alt.Chart(data, width=width).mark_bar().encode(
github altair-viz / altair / altair / examples / layered_plot_with_dual_axis.py View on Github external
alt.X('month(date):O',
        axis=alt.Axis(format='%b'),
        scale=alt.Scale(zero=False)
    )
)

bar = base.mark_bar().encode(
    y='mean(precipitation)'
)


line =  base.mark_line(color='red').encode(
    y='mean(temp_max)',
)

alt.layer(
    bar,
    line
).resolve_scale(
    y='independent'
)
github altair-viz / altair / altair / examples / multiline_tooltip.py View on Github external
)

# Draw text labels near the points, and highlight based on selection
text = line.mark_text(align='left', dx=5, dy=-5).encode(
    text=alt.condition(nearest, 'y:Q', alt.value(' '))
)

# Draw a rule at the location of the selection
rules = alt.Chart().mark_rule(color='gray').encode(
    x='x:Q',
).transform_filter(
    nearest
)

# Put the five layers into a chart and bind the data
alt.layer(line, selectors, points, rules, text,
          data=source, width=600, height=300)
github inferne / notes / tensorflow / RecommendationSystems.py View on Github external
nearest = alt.selection(
      type='single', encodings=['x', 'y'], on='mouseover', nearest=True,
      empty='none')
  base = alt.Chart().mark_circle().encode(
      x=x,
      y=y,
      color=alt.condition(genre_filter, "genre", alt.value("whitesmoke")),
  ).properties(
      width=600,
      height=600,
      selection=nearest)
  text = alt.Chart().mark_text(align='left', dx=5, dy=-5).encode(
      x=x,
      y=y,
      text=alt.condition(nearest, 'title', alt.value('')))
  return alt.hconcat(alt.layer(base, text), genre_chart, data=data)
github wehr-lab / autopilot / autopilot / viz / psychometric.py View on Github external
acc_points = alt.Chart().encode(
        alt.X('x:Q',scale=alt.Scale(type='sqrt'), title=var),
        y=alt.Y('y:Q',title="mean response")
    ).transform_filter(
        alt.FieldEqualPredicate('responses', 'type')
    ).mark_point()

    log_curves = alt.Chart().encode(
        alt.X('x:Q',scale=alt.Scale(type='sqrt'), title=var),
        y=alt.Y('y:Q',title="mean response")
    ).transform_filter(
        alt.FieldEqualPredicate('log_regression', 'type')
    ).mark_line()

    combo = alt.layer(acc_points + log_curves, data=combo_df).facet(row='subject:N')
    #combo.sav
    return combo
github xoolive / traffic / traffic / core / structure.py View on Github external
footprint: bool = True,
        runways: bool = False,
        labels: bool = False,
    ) -> alt.Chart:  # coverage: ignore
        cumul = []
        if footprint:
            cumul.append(super().geoencode())
        if runways:
            cumul.append(self.runways.geoencode())
        if labels:
            cumul.append(self.runways.geoencode("labels"))
        if len(cumul) == 0:
            raise TypeError(
                "At least one of footprint, runways and labels must be True"
            )
        return alt.layer(*cumul)
github piccolbo / altair_recipes / altair_recipes / common.py View on Github external
def layer(*layers, **kwargs):
    """Layer charts: a drop in replacement for altair.layer that does a deepcopy of the layers to avoid side-effects and lifts identical datasets one level down to top level."""
    layers = [l.copy() for l in layers]
    data = layers[0].data
    if all(map(lambda l: data.equals(l.data), layers)):
        layered = alt.layer(*layers, **kwargs, data=data)
        for l in layered.layer:
            del l._kwds["data"]
    else:
        layered = alt.layer(*layers, **kwargs)

    return layered
github onlyphantom / pedagogy / app / analytics.py View on Github external
).add_selection(
        nearest
    )
    points = line.mark_point().encode(
        opacity=alt.condition(nearest, alt.value(1), alt.value(0))
    )
    text = line.mark_text(align='left', dx=-20, dy=-5).encode(
        text=alt.condition(nearest, 'cumsum:Q', alt.value(' '))
    )
    rules = alt.Chart().mark_rule(color='gray').encode(
        x=alt.X("workshop_start:T"),
    ).transform_filter(
        nearest
    )

    upper = alt.layer(line, selectors, points, rules, text, data=dat, width=350)
    lower = alt.Chart().mark_area(color='#75b3cacc').encode(
            x=alt.X("workshop_start:T", axis=alt.Axis(title=''), scale={
                'domain':brush.ref()
            }),
            y=alt.Y("cumsum", axis=alt.Axis(title=''))
        ).properties(
        height=30,
        width=350
    ).add_selection(
        brush
    )

    chart = alt.vconcat(upper,lower, data=dat).configure_view(
        strokeWidth=0
    )
    return chart.to_json()
github altair-viz / altair / altair / examples / selection_layer_bar_month.py View on Github external
bars = alt.Chart().mark_bar().encode(
    x='month(date):O',
    y='mean(precipitation):Q',
    opacity=alt.condition(brush, alt.OpacityValue(1), alt.OpacityValue(0.7))
).add_selection(
    brush
)

line = alt.Chart().mark_rule(color='firebrick').encode(
    y='mean(precipitation):Q',
    size=alt.SizeValue(3)
).transform_filter(
    brush
)

alt.layer(bars, line, data=source)