46 Seaborn
46 Seaborn
Importing Datasets
We have imported the required libraries. In this section, we will understand how
to import the required datasets.
Seaborn comes with a few important datasets in the library. When Seaborn is
installed, the datasets download automatically.
You can use any of these datasets for your learning. With the help of the
following function you can load the required dataset
load_dataset()
seaborn.regplot() method:
seaborn.Implot() method:
# loading dataset
data = sns.load_dataset("mpg")
print(data)
# draw regplot
sns.regplot(x = "mpg",
y = "acceleration",
data = data)
x and y parameters are specified to provide values for the x and y axes.
sns.set_style() is used to have a grid in the background instead of a
default white background. The data parameter is used to specify the
source of information for drawing the plots.
sns.set_style('whitegrid')
sns.lmplot(x ='total_bill', y ='tip', data = dataset,
hue ='sex', markers =['o', 'v'])
sns.set_style('whitegrid')
sns.lmplot(x ='total_bill', y ='tip', data = dataset, hue ='sex',
markers =['o', 'v'], scatter_kws ={'s':100},
palette ='plasma')
In this example what seaborn is doing is that its calling the matplotlib
parameters indirectly to affect the scatter plots. We specify a parameter
called scatter_kws. We must note that the scatter_kws parameter changes
the size of only the scatter plots and not the regression lines. The
regression lines remain untouched. We also use the palette parameter to
change the color of the plot.
regplot lmplot
# loading dataset
data = sns.load_dataset("mpg")
print(data
# draw regplot
sns.regplot(x = "mpg",y = "acceleration", data = data)
# draw regplot
sns.lmplot(x = "mpg",y = "acceleration",data = data)