What do we see in fashion?
๐ Getting the data
#import packages
import pandas as pd
import altair as alt
import numpy as np
#import data
covermodels = pd.read_csv('covermodels.csv', sep = ';')
covermodels.head()
Run to view results
covermodels = covermodels.rename(columns={"Month of Date": "Month", "Year of Date":"Year", "Model Name":"Model"})
covermodels.head()
Run to view results
# create a simple scatterplot first
alt.Chart(covermodels).mark_circle().encode(
# position based on population and elevation:
x='Year:O',
y='Race/Ethnicity:O',
opacity= alt.value(0.6),
color = "Publication"
).interactive()
Run to view results
๐บ Presenting data
# creating a dropdown element with the magazines
magazines = covermodels.Publication.unique()
dropdown = alt.binding_select(options=magazines, name="Select a magazine ")
# applying the selection to the magazine column and using the dropwdown element
selection = alt.selection(type="single", fields=['Publication'], bind=dropdown, init={'Publication':'Vogue'})
#creating a base
base = alt.Chart(covermodels).properties(width=320, height=250)
#now I will create a scatter plot
overall_line = base.mark_line().encode(
x='Year:O',
y ='count(Year)',
color = alt.Color("Race/Ethnicity", legend=alt.Legend(title="Race/Ethnicity of Covermodel"))
).properties(
title='All magazines'
).add_selection(selection).interactive()
interactive_scat = base.mark_circle().encode(
x='Year:O',
y='count(Year)',
color='Race/Ethnicity',
).properties(
title='Select a magazine'
).add_selection(
selection
).transform_filter(
selection
)
interactive_scat | overall_line
Run to view results
# creating a dropdown element with the magazines
magazines = covermodels.Publication.unique()
dropdown = alt.binding_select(options=magazines, name="Select a magazine ")
# applying the selection to the magazine column and using the dropwdown element
selection = alt.selection(type="single", fields=['Publication'], bind=dropdown, init={'Publication':'Vogue'})
#now I will create a scatter plot
alt.Chart(covermodels).mark_bar().encode(
x='Year:O',
#y=alt.Y(aggregate='count',field='Publication',type='quantitative'),
#y =alt.Y('count(Year)'),
y ='Month',
color = "Race/Ethnicity",
tooltip = ["Month","Year","Model"],
#facet='Publication:N',
opacity=alt.condition(selection, alt.value(1), alt.value(0))
).add_selection(selection).interactive()
Run to view results