#!/usr/bin/env python # coding: utf-8 # In[38]: import altair as alt import pandas as pd from vega_datasets import data # In[3]: df = pd.DataFrame({ 'Name': ['Big M*c', 'Lg Supreme Pizza', '12" Veggie Delite', "500ml Coke"], 'Calories': [540, 350, 460, 210], 'Fat': [28, 17, 6, 0], 'Sugar': [9, 2, 12, 53] }) # In[16]: alt.Chart( df, padding=20, background='#fff' ).mark_bar( ).encode( x='Name', y='Calories' ).properties( width=150, height=200 ) # In[12]: alt.Chart( df, padding=20, background='#fff' ).mark_circle( ).encode( x='Fat', y='Sugar', size='Calories' ).properties( width=200, height=00 ) # In[37]: base = alt.Chart( df, ).encode( x='Name' ).properties( width=150, height=200 ) cal = base.mark_bar( ).encode( y=alt.Y('Calories', axis=alt.Axis(orient='left')), ) sugar = base.mark_line( color='orange' ).encode( y=alt.Y('Sugar', axis=alt.Axis(orient='right')), ) (cal + sugar).resolve_scale( y='independent' ).configure( padding=20, background='#fff' ) # In[39]: source = data.movies.url alt.Chart( source, padding=20, background='#fff' ).mark_bar( ).encode( alt.X("IMDB_Rating:Q", bin=True), y='count()', ) # In[ ]: source = data.movies.url alt.Chart( source, padding=20, background='#fff' ).mark_bar( ).encode( alt.X("IMDB_Rating:Q", bin=True), y='average(Worldwide_Gross):Q', ) # In[ ]: