Python Seaborn Tutorial - Jupyter Notebook
Python Seaborn Tutorial - Jupyter Notebook
Python Seaborn Tutorial - Jupyter Notebook
In [1]:
In [2]:
0.11.0
In [3]:
iris_df = sns.load_dataset('iris')
iris_df.head()
Out[3]:
In [4]:
iris_df['species'].unique()
Out[4]:
In [5]:
sns.scatterplot(x='sepal_length',y='sepal_width',hue='species',data=iris_df)
plt.show()
In [6]:
sns.scatterplot(x='petal_length',y='petal_width',hue='species',data=iris_df)
plt.show()
In [7]:
df=sns.load_dataset("fmri")
df.head()
Out[7]:
In [8]:
df.shape
Out[8]:
(1064, 5)
In [9]:
stim = df[df['event']=='stim']
cue = df[df['event']=='cue']
In [10]:
stim.head()
Out[10]:
In [11]:
cue.head()
Out[11]:
In [13]:
df.event.unique()
Out[13]:
In [14]:
df['region'].unique()
Out[14]:
In [15]:
sns.lineplot(x="timepoint",y="signal",data=df)
plt.title('My LinePlot')
plt.show()
In [16]:
sns.lineplot(x="timepoint",y="signal",data=df,hue="event")
plt.show()
In [17]:
sns.lineplot(x="timepoint",y="signal",data=df,hue="event",style="event",markers=True)
plt.show()
In [18]:
import pandas as pd
df1=pd.read_csv("iris.csv")
df1.head()
Out[18]:
In [19]:
df1['species'].unique()
Out[19]:
In [20]:
sns.distplot(df1['sepal_length'])
plt.grid(True)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2551: Fu
tureWarning: `distplot` is a deprecated function and will be removed in a fu
ture version. Please adapt your code to use either `displot` (a figure-level
function with similar flexibility) or `histplot` (an axes-level function for
histograms).
warnings.warn(msg, FutureWarning)
In [21]:
df1.species.unique()
Out[21]:
In [22]:
sns.pairplot(data=df1,hue='species')
plt.show()
In [23]:
sns.scatterplot(x="sepal_length",y="petal_width",data=df1,hue="species",style="species")
plt.show()
In [24]:
sns.swarmplot(x="species",y="petal_length",data=df1)
plt.grid(True)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\categorical.py:1296: User
Warning: 14.0% of the points cannot be placed; you may want to decrease the
size of the markers or use stripplot.
warnings.warn(msg, UserWarning)
In [25]:
df2=sns.load_dataset("flights")
df2.head()
Out[25]:
In [26]:
df2.shape
Out[26]:
(144, 3)
In [27]:
sns.relplot(x="passengers",y="month",data=df2)
plt.show()
In [28]:
sns.set_style('darkgrid')
sns.color_palette("tab10")
df3=sns.load_dataset("flights")
sns.relplot(x="passengers",y="month",hue="year",data=df3)
plt.show()
In [29]:
df4=sns.load_dataset("tips")
df4.head()
Out[29]:
In [30]:
df4.time.unique()
Out[30]:
['Dinner', 'Lunch']
In [31]:
sns.boxplot(df4.total_bill)
plt.grid(True)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\_decorators.py:36: Future
Warning: Pass the following variable as a keyword arg: x. From version 0.12,
the only valid positional argument will be `data`, and passing other argumen
ts without an explicit keyword will result in an error or misinterpretation.
warnings.warn(
In [32]:
sns.relplot(x="total_bill",y="tip",hue="time",data=df4)
plt.show()
In [34]:
sns.relplot(x="time",y="tip",kind="line",data=df4)
plt.show()
In [35]:
sns.catplot(x=df4["day"],y=df4["total_bill"],data=df4)
plt.show()
In [36]:
sns.catplot(x="day",y="total_bill",kind="boxen",data=df4)
plt.show()
In [37]:
sns.catplot(x="day",y="total_bill",kind="violin",data=df4)
plt.show()
In [38]:
sns.boxplot(x="day",y="total_bill",data=df4)
plt.show()
In [39]:
a=sns.load_dataset("iris")
b=sns.FacetGrid(a,col="species")
b.map(plt.hist,"sepal_length")
plt.show()
In [40]:
a=sns.load_dataset("flights")
b=sns.PairGrid(a)
b.map(plt.scatter)
plt.show()
In [46]:
#ColorPalette
c=sns.color_palette()
sns.palplot(c)
In [47]:
l = [0, 1, 2, 3, 4, 5]
sns.distplot(l)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2551: Fu
tureWarning: `distplot` is a deprecated function and will be removed in a fu
ture version. Please adapt your code to use either `displot` (a figure-level
function with similar flexibility) or `histplot` (an axes-level function for
histograms).
warnings.warn(msg, FutureWarning)
In [48]:
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2551: Fu
tureWarning: `distplot` is a deprecated function and will be removed in a fu
ture version. Please adapt your code to use either `displot` (a figure-level
function with similar flexibility) or `kdeplot` (an axes-level function for
kernel density plots).
warnings.warn(msg, FutureWarning)
In [49]:
print(x)
[7 7 7 4 7 6 3 5 5 3]
In [50]:
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2551: Fu
tureWarning: `distplot` is a deprecated function and will be removed in a fu
ture version. Please adapt your code to use either `displot` (a figure-level
function with similar flexibility) or `kdeplot` (an axes-level function for
kernel density plots).
warnings.warn(msg, FutureWarning)
In [ ]: