alt.Chart(missing).mark_bar().encode( x=alt.X('Column', sort='-y'), y='Count missing', color=alt.condition( alt.datum['Count missing'] >10, # If count missing is > 10%, returns True, alt.value('orange'), # which sets the bar orange. alt.value('steelblue') # And if it's not true it sets the bar steelblue. ), tooltip=['Count missing']).properties( width=500, height=300).configure_axis( grid=False)
Boxplot
Creation of a basic boxplot using .mark_boxplot() method
A Dot Dash Plot is basically a scatter plot with both axis removed and replaced with barcode plots (aka strip plots), which allow you to see the distribution of values of each measure used in the scatter plot.
# Configure the options common to all layersbrush = alt.selection_interval()base = alt.Chart(train).add_params(brush)# Configure the pointspoints = base.mark_point().encode( x=alt.X('GrLivArea', title=''), y=alt.Y('SalePrice', title=''), color=alt.condition(brush, 'KitchenQual', alt.value('grey')))# Configure the tickstick_axis = alt.Axis(labels=False, domain=False, ticks=False)x_ticks = base.mark_tick().encode( alt.X('GrLivArea', axis=tick_axis), alt.Y('KitchenQual', title='', axis=tick_axis), color=alt.condition(brush, 'KitchenQual', alt.value('lightgrey')))y_ticks = base.mark_tick().encode( alt.X('KitchenQual', title='', axis=tick_axis), alt.Y('SalePrice', axis=tick_axis), color=alt.condition(brush, 'KitchenQual', alt.value('lightgrey')))# Build the chart( y_ticks | (points & x_ticks)).configure_axis( grid=False)
Multifeature Scatter Plot
Let’s create a scatter plot with multiple feature encodings.
With .interactive() you can zoom in. You can also click on legend to select specific KitchenQual values.
Scatter matrix are one of the most common graph you’ll see on Kaggle. It consists of several pair-wise scatter plots of variables presented in a matrix format, useful to visualize multiple relationships between a pair of variables.
In Altair this can be achieved using a RepeatChart, let’s see how!
alt.Chart(train).mark_circle().encode( alt.X(alt.repeat("column"), type='quantitative'), alt.Y(alt.repeat("row"), type='quantitative'), color='KitchenQual').properties( width=300, height=300).repeat(# Here we tell Altair we want to repeat out scatter plots for each row-column pair row=['GrLivArea', 'GarageArea', 'TotalBsmtSF'], column=['TotalBsmtSF', 'GarageArea', 'GrLivArea']).configure_axis( grid=False)
Layered Histogram
Using Altair, we can make overlapping histograms or layers histograms from data: