df=data.iris() # Itto is pretty smart
df
fig, ax = plt.subplots()
colors=['#1f77b4', '#ff7f0e', '#2ca02c']
for color, species in zip(colors, df.species.unique()):
tmp = df[df.species == species]
ax.scatter(tmp.petalLength, tmp.petalWidth,
label=species, color=color)
ax.set(xlabel='Petal Length',
ylabel='Petal Width',
title='Petal Width v. Length -- by Species')
ax.legend(loc=2);
alt.Chart(df).mark_circle().encode(
x='petalLength',
y='petalWidth',
color='species'
)
alt.Chart(df).mark_circle().encode(
x='petalLength',
y='petalWidth'
)
alt.Chart(fake_data).mark_image(width=50).encode(
x='Beauty',
y='Number of letters:N',
url='img'
).properties(title="Notebook logo metrics")
alt.Chart(df).mark_point().encode(
x='petalWidth',
y='petalLength',
shape='species',
color='species'
#color='species' # shape, opacity, color, tooltips, size
)
cars=data.cars()
alt.Chart(cars).mark_circle().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Cylinders:O' #O, N, Q
)
alt.Chart(df).mark_bar().encode(
x='mean(petalWidth)', #sum, max, mean, variance, ci0, etc...
y='species',
color='species'
)
stocks=data.stocks()
stocks
alt.Chart(stocks).mark_line().encode(
x='quarter(date)', #month, year, quarter, yearmonth
y='mean(price)',
color='symbol'
)
bar=alt.Chart(df).mark_bar().encode(
x='mean(petalWidth)',
y='species',
color='species'
)
point=alt.Chart(df).mark_point().encode(
x='petalWidth',
y='petalLength',
color='species'
)
point | bar
bar=alt.Chart(df).mark_bar().encode(
x='mean(petalWidth)',
y='species',
color='species'
)
mean=alt.Chart(df).mark_rule().encode(
x='mean(petalWidth)',
)
bar + mean
circle=alt.Chart(df).mark_circle(size=400).encode(
x='mean(petalWidth)',
y='mean(petalLength)',
color='species'
)
point=alt.Chart(df).mark_point().encode(
x='petalWidth',
y='petalLength',
color='species'
)
point + circle
alt.Chart(df).mark_circle().encode(
x=alt.X('petalLength'),
y=alt.Y('petalWidth')
)
alt.Chart(df).mark_circle().encode(
x=alt.X('petalLength', scale=alt.Scale(domain=[-4,10])),
y=alt.Y('petalWidth', axis=alt.Axis(labelColor='red')),
color=alt.Color('species', legend=alt.Legend(labelColor='blue'))
)
alt.Chart(df).mark_point(filled=True, color='green', size=300).encode(
x=alt.X('petalLength', axis=alt.Axis(labelColor='red')),
y=alt.Y('petalWidth', axis=alt.Axis(labelColor='blue')),
shape=alt.Shape('species', legend=alt.Legend(labelColor='grey'))
).properties(title='Long form of API & adjusted properties', width=300, height=300)
alt.Chart(df).mark_bar().encode(
x=alt.X('sepalLength', bin=True), #alt.Bin(maxmins=25)
y='count()'
)
alt.Chart(df).mark_rect().encode(
x=alt.X('sepalLength', bin=True), #alt.Bin(maxmins=25)
y=alt.X('sepalWidth', bin=True), #alt.Bin(maxmins=25)
color='count()'
)
iowa_1=data.iowa_electricity()
iowa_1
iowa_2=data.iowa_electricity()
iowa_2
cars_1=data.cars()
cars_1
cars_2=data.cars()
cars_2
cars_3=data.cars()
cars_3
cars_4=data.cars()
cars_4
barley_1=data.barley()
barley_1
iowa_3=data.iowa_electricity()
iowa_3
birds_1=data.birdstrikes().sample(500, random_state=42)
birds_1
crimea_1=data.crimea()
crimea_1
weather_1=data.seattle_temps().sample(1000, random_state=42)
weather_1
alt.Chart(weather_1).mark_line().encode(
x='month(date):T',
y='mean(temp)',
)
alt.Chart(weather_1).mark_line().encode(
y='mean(temp)',
x='month(date)'
)
cars_5 = data.cars()
cars_5
birds_2= data.birdstrikes().sample(1000, random_state=42)
birds_2
birds_3= data.birdstrikes().sample(1000, random_state=42)
birds_3
ansc_1=data.anscombe()
ansc_1
barley_2=data.barley()
barley_2
barley_3=data.barley()
barley_3
birds_4=data.birdstrikes().sample(500, random_state=42)
birds_4
barley_4=data.barley()
barley_4
weather_2=data.seattle_weather()
weather_2
iris_1=data.iris()
iris_1
stocks_1=data.stocks()
stocks_1
movies_1=data.movies()
movies_1
unemp_1=data.unemployment_across_industries()
unemp_1.loc[unemp_1['series'] == 'Government']
barley_5=data.barley()
barley_5
unemp_2=data.unemployment_across_industries()
unemp_2
imdb_2= data.movies()
imdb_2
unemp_3=data.unemployment_across_industries()
unemp_3
cars_6 = data.cars()
cars_6
barley_6 = data.barley()
barley_6
url = data.population.url
pop_1 = pd.read_json(url)
pop_1