Hands On Seaborn?
Hands On Seaborn?
import numpy as np
Line Plot
temperature = [36.6,37,37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
plt.show()
tips_df.head()
plt.show()
sns.set(style = 'darkgrid')
plt.xlabel('Size',fontsize = 15)
plt.legend(loc = 2)
plt.show()
sns.set(style = 'darkgrid')
plt.xlabel('Size',fontsize = 15)
plt.legend(loc = 2)
plt.show()
ax = plt.axes()
ax.set_facecolor('black')
# plt.figure(figsize = (15,9))
sns.set(style = 'darkgrid')
plt.legend(loc = 2)
plt.show()
In [8]: tips_df.head()
In [9]: sns.distplot(tips_df['size'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
In [10]: sns.distplot(tips_df['tip'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o 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 [12]: sns.distplot(tips_df['total_bill'],kde = False)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o 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 [14]: sns.distplot(tips_df['total_bill'],fit = norm,hist = True,color = 'red',axlab
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:1689: FutureWarning: The `vertical` parameter
is deprecated and will be removed in a future version. Assign the data to th
e `y` variable instead.
warnings.warn(msg, FutureWarning)
In [16]: # plt.figure(facecolor = 'red')
# ax = plt.axes()
# ax.set_facecolor('black')
plt.figure(figsize = (15,9))
plt.legend('Total Bill')
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
ax = plt.axes()
ax.set_facecolor('black')
# plt.figure(figsize = (15,9))
plt.legend('Total Bill')
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
In [18]: tips_df.total_bill.sort_values()
67 3.07
Out[18]:
92 5.75
111 7.25
172 7.25
149 7.51
...
182 45.35
156 48.17
59 48.27
212 48.33
170 50.81
Name: total_bill, Length: 244, dtype: float64
# plt.figure(figsize = (15,9))
# plt.xticks(bins)
plt.legend('Total Bill')
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
In [20]: plt.figure(facecolor = 'pink')
ax = plt.axes()
ax.set_facecolor('black')
# plt.xticks(bins)
plt.legend('Total Bill')
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
ax = plt.axes()
ax.set_facecolor('black')
# plt.xticks(bins)
plt.legend('Total Bill')
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2103: FutureWarning: The `axis` variable is no
longer used and will be removed. Instead, assign variables directly to `x` o
r `y`.
warnings.warn(msg, FutureWarning)
Bar Plot
In [22]: tips_df.head()
plt.show()
plt.show()
hue_order = ['Male','Female']
In [26]: # Mean
In [27]: # Max
In [28]: # STD
In [29]: # Sum
In [30]: # Min
# plt.show()
errwidth = 2)
xlabel = 'Days',
errwidth = 2)
# plt.savefig()
plt.show()
ax = plt.axes()
ax.set_facecolor('white')
#plt.figure(figsize = (16,9))
errwidth = 1)
# plt.savefig()
plt.show()
Scatter Plot
In [44]: titanic_df = pd.read_csv('titanic.csv')
titanic_df.head()
Out[44]: survived pclass sex age sibsp parch f are embarked class who adult _male de
plt.show()
plt.show()
# ax = plt.axes()
# ax.set_facecolor('white')
# plt.show()
Heatmap
arr_2d
In [51]: sns.heatmap(arr_2d)
plt.show()
globalwarming_df.head()
CO2
emissions
United
0 USA (metric EN.AT M.CO2E.PC 20.178751 19.636505 19.613404 19.564105
States
tons per
capita)
CO2
emissions
United
1 GBR (metric EN.AT M.CO2E.PC 9.199549 9.233175 8.904123 9.053278
Kingdom
tons per
capita)
CO2
emissions
2 India IND (metric EN.AT M.CO2E.PC 0.979870 0.971698 0.967381 0.992392
tons per
capita)
CO2
emissions
3 China CHN (metric EN.AT M.CO2E.PC 2.696862 2.742121 3.007083 3.524074
tons per
capita)
CO2
emissions
Russian
4 RUS (metric EN.AT M.CO2E.PC 10.627121 10.669603 10.715901 11.090647
Federation
tons per
capita)
Co unt ry
Name
Unit ed
20.178751 19.636505 19.613404 19.564105 19.658371 19.591885 19.094067 19.2178
St at es
Unit ed
9.199549 9.233175 8.904123 9.053278 8.989140 8.982939 8.898710 8.617
Kingdo m
Russian
10.627121 10.669603 10.715901 11.090647 11.120627 11.253529 11.669122 11.6724
Federat io n
sns.heatmap(globalwarming_df)
plt.show()
# plt.show()
# plt.show()
In [62]: # plt.figure(figsize=(14,14))
# cbar_kws = {"orientation":"horizontal",
# "shrink":1,
# 'extend':'min',
# 'extendfrac':0.1,
# "ticks":np.arange(0,22),
# "drawedges":True,
# }
# sns.heatmap(globalwarming_df, cbar_kws=cbar_kws)
# plt.show()
In [63]: # plt.figure(figsize=(16,9))
# ax = sns.heatmap(globalwarming_df,)
# ax.set(title="Heatmap",
# xlabel="Years",
# ylabel="Country Name",)
Correlation
In [64]: globalwarming_df.corr()
Out[64]: 2000 2001 2002 2003 2004 2005 2006 2007 2008
2000 1.000000 0.999632 0.999155 0.998911 0.998314 0.997008 0.994087 0.992283 0.987767
2001 0.999632 1.000000 0.999229 0.999026 0.998095 0.996628 0.993860 0.991532 0.987057
2002 0.999155 0.999229 1.000000 0.998907 0.998399 0.997391 0.995643 0.994017 0.990034
2003 0.998911 0.999026 0.998907 1.000000 0.999568 0.998887 0.996614 0.995277 0.991681
2004 0.998314 0.998095 0.998399 0.999568 1.000000 0.999701 0.998105 0.997144 0.993891
2005 0.997008 0.996628 0.997391 0.998887 0.999701 1.000000 0.998942 0.998420 0.995803
2006 0.994087 0.993860 0.995643 0.996614 0.998105 0.998942 1.000000 0.999570 0.998415
2007 0.992283 0.991532 0.994017 0.995277 0.997144 0.998420 0.999570 1.000000 0.999088
2008 0.987767 0.987057 0.990034 0.991681 0.993891 0.995803 0.998415 0.999088 1.000000
2009 0.980143 0.978912 0.983584 0.984511 0.987300 0.990125 0.994104 0.995724 0.998145
2010 0.979172 0.978562 0.982944 0.984466 0.987668 0.990498 0.994985 0.996367 0.998539
2011 0.967887 0.967206 0.972479 0.975128 0.979061 0.982646 0.988553 0.990928 0.994593
2012 0.961582 0.961625 0.967161 0.969919 0.974094 0.977758 0.984892 0.986978 0.991128
2013 0.962466 0.962827 0.967573 0.971053 0.975276 0.978611 0.984857 0.986819 0.989983
2014 0.962331 0.961622 0.965665 0.970508 0.975061 0.978521 0.983371 0.986199 0.988927
In [65]: # plt.figure(figsize=(16,9))
# ax = sns.heatmap(globalwarming_df.corr(),annot = True,linewidths = 2)
# plt.show()
In [66]: plt.figure(figsize=(16,9))
plt.show()
In [68]: breast_cancer.corr()
31 rows × 31 columns
# sns.heatmap(breast_cancer.corr(),annot = True,linewidths = 2)
# plt.show()
Pairplot
In [77]: # sns.pairplot(breast_cancer)
# plt.show()
In [80]: # sns.pairplot(breast_cancer.corr())
# plt.show()
In [82]: breast_cancer.describe()
8 rows × 31 columns
sns.pairplot(breast_cancer[featureMeans].corr(),diag_kind = 'kde',size = 2)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\axisgrid.py:2076: UserWarning: The `size` parameter has been re
named to `height`; please update your code.
warnings.warn(msg, UserWarning)
In [92]: plt.figure(figsize = (10,10))
CampusX
In [2]: import seaborn as sns
import numpy as np
import pandas as pd
In [3]: plt.style.use('fivethirtyeight')
tips_df.head()
Scatter Plot
plt.show()
plt.show()
plt.show()
plt.show()
plt.show()
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\categorical.py:1296: UserWarning: 8.1% of the points cannot be
placed; you may want to decrease the size of the markers or use stripplot.
warnings.warn(msg, UserWarning)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\categorical.py:1296: UserWarning: 8.1% of the points cannot be
placed; you may want to decrease the size of the markers or use stripplot.
warnings.warn(msg, UserWarning)
In [119… # sns.swarmplot(x = 'day',y = 'tip',data = tips_df)
# plt.show()
Box Plot
In [5]: sns.boxplot(tips_df['tip'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\_decorators.py:36: FutureWarning: Pass the following variable a
s a keyword arg: x. From version 0.12, the only valid positional argument wi
ll be `data`, and passing other arguments without an explicit keyword will r
esult in an error or misinterpretation.
warnings.warn(
In [6]: sns.boxplot(tips_df['total_bill'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\_decorators.py:36: FutureWarning: Pass the following variable a
s a keyword arg: x. From version 0.12, the only valid positional argument wi
ll be `data`, and passing other arguments without an explicit keyword will r
esult in an error or misinterpretation.
warnings.warn(
plt.show()
Violin Plot
In [9]: sns.violinplot(tips_df['total_bill'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\_decorators.py:36: FutureWarning: Pass the following variable a
s a keyword arg: x. From version 0.12, the only valid positional argument wi
ll be `data`, and passing other arguments without an explicit keyword will r
esult in an error or misinterpretation.
warnings.warn(
In [10]: sns.catplot(x = 'day',y = 'total_bill',kind = 'violin',data = tips_df)
plt.show()
plt.show()
plt.show()
plt.show()
Heatmap
In [33]: plt.style.use('fivethirtyeight')
flights_df.head()
sns.heatmap(x)
plt.show()
plt.show()
plt.show()
plt.show()
Clustermap
In [45]: sns.clustermap(x)
plt.show()
plt.show()
Joint Plot
plt.show()
plt.show()
plt.show()
plt.show()
plt.show()
Pair Plot
In [63]: plt.style.use('fivethirtyeight')
iris_df.head()
In [65]: sns.pairplot(iris_df)
plt.show()
plt.show()
Dist Plot
In [68]: plt.style.use('fivethirtyeight')
titanic_df.head()
Out[69]: survived pclass sex age sibsp parch f are embarked class who adult _male de
In [76]: sns.distplot(titanic_df['age'])
plt.show()
plt.show()
plt.show()
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`kdeplot` (an axes-level function for kernel density plots).
warnings.warn(msg, FutureWarning)
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2103: FutureWarning: The `axis` variable is no
longer used and will be removed. Instead, assign variables directly to `x` o
r `y`.
warnings.warn(msg, FutureWarning)
In [85]: sns.distplot(titanic_df[titanic_df['survived']==1]['age'])
sns.distplot(titanic_df[titanic_df['survived']==0]['age'])
plt.show()
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\prasad jadhav\AppData\Local\Programs\Python\Python310\lib\site-pack
ages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecate
d function and will be removed in a future version. Please adapt your code t
o use either `displot` (a figure-level function with similar flexibility) or
`histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
Thank You