Search code examples
pythonvisualizationrepeataltair

How to show part of the repeated chart in altair


i have used repeat in altair and the Result looks like this.

enter image description here

i was wondering how can i only show the Lower part that i have marked with a Red triangle.

the code that i have used:

from sklearn import datasets
import altair as alt

data_wine = datasets.load_wine (as_frame = True).frame
features = data_wine.columns.values[data_wine.columns.values != 'target']
    
alt.Chart(data_wine).mark_circle().encode(
    alt.X(alt.repeat("column"), type = 'quantitative', scale = alt.Scale (nice = True)),
    alt.Y(alt.repeat("row"), type = 'quantitative', scale = alt.Scale (nice = True)),
    color = 'target:N'
).properties(
    width=150,
    height=150
).repeat(
    row = features,
    column = features
)#.interactive()

Solution

  • It seems that altair can't do it by itself. The reason is confirmed https://github.com/altair-viz/altair/issues/2321: There is an experimental wrapper package with a more terse syntax for common exploratory plots that you could try out. See https://joelostblom.github.io/altair_ally/examples.html.

    from sklearn import datasets
    import altair as alt
    import altair_ally as aly
    
    data_wine = datasets.load_wine (as_frame = True).frame
    features = data_wine.columns.values[data_wine.columns.values != 'target']
    data_wine['target'] = data_wine['target'].astype(str)
    
    aly.pair(data_wine,'target')
    

    enter image description here