Seaborn
Seaborn
org/
Seaborn is a library for making statistical graphics in Python. It builds on top of matplotlib and
integrates closely with pandas data structures.
Seaborn Vs Matplotlib
Seaborn smatter than the matpotlib and plot graphs beautiful with less coding. You can do
the same work with matplotlib but it is difficult because it has no such built-in function.
['anagrams',
Out[2]:
'anscombe',
'attention',
'brain_networks',
'car_crashes',
'diamonds',
'dots',
'dowjones',
'exercise',
'flights',
'fmri',
'geyser',
'glue',
'healthexp',
'iris',
'mpg',
'penguins',
'planets',
'seaice',
'taxis',
'tips',
'titanic']
Bar Plot
Bar plots are a type of data visualization used to represent data in the form of rectangular
bars. The height of each bar represents the value of a data point, and the width of each bar
represents the category of the data.
<seaborn.axisgrid.FacetGrid at 0x1419b102da0>
Out[10]:
Count Plot
Count plot can be thought of as a histogram across a categorical, instead of quantitative,
variable. The basic API and options are identical to those for barplot(), so you can compare
counts across nested variables.
Rug is not really a separate plot. It is a one-dimensional display that you can add to existing
plots to illuminate information that is sometimes lost in other types of graphs. Like a strip
plot, it represents values of a variable by putting a symbol at various points along an axis.
However, it uses short lines to represent points.
<seaborn.axisgrid.PairGrid at 0x1419d062f50>
Out[13]:
Joint Plot
Joint plot is a way of understanding the relationship between two variables and the
distribution of individuals of each variable. The joint plot mainly consists of three separate
plots in which, one of it was the middle figure that is used to see the relationship between x
and y. So, this area will give the information about the joint distribution, while the remaining
two areas will provide us with the marginal distribution for the x-axis and y-axis.
<seaborn.axisgrid.JointGrid at 0x1419d711030>
Out[14]:
Heatmap / Matrix Plot
Heatmap is a 2D graphical representation of data where the individual values that are
contained in a matrix are represented as colours. The color of the matrix is dependent on
value. Normally, low-value show in low-intensity color and high-value show in hight-intensity
color format.
... ... ... ... ... ... ... ... ... ... ... ... ...
<Axes: >
Out[17]:
TASK:
Generate general heatmap for "global_warming.csv" dataset. (For styling, set arguments as
much as you want)
CO2
emissions
0 United USA
States (metric EN.ATM.CO2E.PC 20.178751 19.636505 19.613404 19.564105 19.658371 19.5918
tons per
capita)
CO2
emissions
1 United GBR
Kingdom (metric EN.ATM.CO2E.PC 9.199549 9.233175 8.904123 9.053278 8.989140 8.9829
tons per
capita)
2 India IND CO2 EN.ATM.CO2E.PC 0.979870 0.971698 0.967381 0.992392 1.025028 1.0685
emissions
(metric
tons per
capita)
CO2
emissions
3 China CHN (metric EN.ATM.CO2E.PC 2.696862 2.742121 3.007083 3.524074 4.037991 4.5231
tons per
capita)
CO2
emissions
Russian
4 RUS (metric EN.ATM.CO2E.PC 10.627121 10.669603 10.715901 11.090647 11.120627 11.2535
Federation
tons per
capita)
In [20]: # Drop non numeric columns and set country column as index
df = df.drop(columns=['Country Code', 'Indicator Name', 'Indicator Code'], axis=1).set_i
df.head()
Out[20]: 2000 2001 2002 2003 2004 2005 2006 2007 2008
Country
Name
United
20.178751 19.636505 19.613404 19.564105 19.658371 19.591885 19.094067 19.217898 18.461764 17
States
United
9.199549 9.233175 8.904123 9.053278 8.989140 8.982939 8.898710 8.617164 8.424424 7
Kingdom
India 0.979870 0.971698 0.967381 0.992392 1.025028 1.068563 1.121982 1.193210 1.310098 1
China 2.696862 2.742121 3.007083 3.524074 4.037991 4.523178 4.980314 5.334910 5.701915 6
Russian
10.627121 10.669603 10.715901 11.090647 11.120627 11.253529 11.669122 11.672457 12.014507 11
Federation
# Create heatmap
sns.heatmap(df, vmin = 0, vmax = 21, cmap="coolwarm", annot = True, linewidth = 2, cbar_