Matrix Plots¶
Matrix plots allow you to plot data as color-encoded matrices and can also be used to indicate clusters within the data (later in the machine learning section we will learn how to formally cluster data).
Let's begin by exploring seaborn's heatmap and clutermap:
In [1]:
import seaborn as sns
%matplotlib inline
flights = sns.load_dataset('flights')
tips = sns.load_dataset('tips')
In [46]:
flights.head(2)
Out[46]:
In [4]:
tips.head(2)
Out[4]:
In [45]:
tips.corr()
#flights.corr()
Out[45]:
In [9]:
tc=tips.corr()
In [47]:
sns.heatmap(tc)
Out[47]:
In [48]:
sns.heatmap(tc,annot=True)
Out[48]:
In [50]:
sns.heatmap(tc,annot=True,cmap='coolwarm')
#tips.head(2)
Out[50]:
In [27]:
tips.pivot_table(values='tip',index='day',columns='sex')
Out[27]:
In [29]:
tips.pivot_table(values='tip',index='day',columns='smoker')
Out[29]:
In [30]:
tips.pivot_table(values='tip',index='day',columns='size')
Out[30]:
In [52]:
flights.head()
Out[52]:
In [53]:
flights.pivot_table(values='passengers',index='month',columns='year')
Out[53]:
In [54]:
fpt = flights.pivot_table(values='passengers',index='month',columns='year')
sns.heatmap(fpt)
Out[54]:
In [55]:
sns.heatmap(fpt,cmap='magma')
Out[55]:
In [58]:
sns.heatmap(fpt,cmap='magma',linecolor='w',linewidths=1)
Out[58]:
No comments:
Post a Comment