Related Articles
Relational plots in Seaborn – Part II
• Last Updated : 08 Jun, 2020

Prerequisite: Relational Plots in Seaborn – Part I

In the previous part of this article, we learnt about the `relplot()`. Now, we will be reading about the other two relational plots, namely `scatterplot()` and `lineplot()` provided in seaborn library. Both these plots can also be drawn with the help of kind parameter in `relplot()`. Basically `relplot()`, by default, gives us scatterplot() only, and if we pass the parameter kind = “line”, it gives us `lineplot()`.

Example 1: Using relplot() to visualize tips dataset

 `import` `seaborn as sns``sns.``set``(style ``=``"ticks"``)``  ` `tips ``=` `sns.load_dataset(``'tips'``)``sns.relplot(x ``=``"total_bill"``, y ``=``"tip"``, data ``=` `tips)`

Output : Example 2: Using relplot() with kind=”scatter”.

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=``"ticks"``) ``tips ``=` `sns.load_dataset(``'tips'``)`` ` `sns.relplot(x ``=``"total_bill"``,``            ``y ``=``"tip"``,``            ``kind ``=``"scatter"``, ``            ``data ``=` `tips)`

Output : Example 3: Using relplot() with kind=”line”.

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=``"ticks"``) ``tips ``=` `sns.load_dataset(``'tips'``)`` ` `sns.relplot(x ``=``"total_bill"``,``            ``y ``=``"tip"``,``            ``kind ``=``"line"``,``            ``data ``=` `tips)`

Output : Though both these plots can be drawn using relplot(), seaborn also have separate functions for visualizing these kind of plots. These functions do provides some other functionalities too, compared to relplot(). Let us discuss about these function in more detail:

## Seaborn.scatterplot()

The scatter plot is a mainstay of statistical visualization. It depicts the joint distribution of two variables using a cloud of points, where each point represents an observation in the dataset. This depiction allows the eye to infer a substantial amount of information about whether there is any meaningful relationship between them.

Syntax :

`seaborn.scatterplot(x=None, y=None, data=None, **kwargs)`

Parameters :

ParameterValueUse
x, ynumericInput data variables
hue, size, stylename in data; optionalGrouping variable that will produce elements with different colors.
palettename, list, or dict; optionalColors to use for the different levels of the hue variable.
hue_orderlist; optionalSpecified order for the appearance of the hue variable levels.
hue_normtuple or Normalize object; optionalNormalization in data units for colormap applied to the hue variable when it is numeric.
sizeslist, dict, or tuple; optionaldetermines the size of each point in the plot.
size_orderlist; optionalSpecified order for appearance of the size variable levels
size_normtuple or Normalize object; optionalNormalization in data units for scaling plot objects when the size variable is numeric.
markersboolean, list, or dictionary; optionalobject determining the shape of marker for each data points.
style_orderlist; optionalSpecified order for appearance of the style variable levels
alphafloatproportional opacity of the points.
legend“brief”, “full”, or False; optionalIf “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values. If “full”, every group will get an entry in the legend. If False, no legend data is added and no legend is drawn.
axmatplotlib axes; optionalAxes object in which the plot is to be drawn.
kwargskey, value pairingsOther keyword arguments are passed through to the underlying plotting function.

Example 1: Plotting a scatterplot using marker to differentiate between timing of the people visiting the restaurant.

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=``"ticks"``) ``tips ``=` `sns.load_dataset(``'tips'``)``markers ``=` `{``"Lunch"``: ``"s"``, ``"Dinner"``: ``"X"``}`` ` `ax ``=` `sns.scatterplot(x ``=``"total_bill"``,``                     ``y ``=``"tip"``, ``                     ``style ``=``"time"``,``                     ``markers ``=` `markers,``                     ``data ``=` `tips)`

Output: Example 2: Passing data vectors instead of names in a data frame.

 `import` `seaborn as sns`` ` ` ` `iris ``=` `sns.load_dataset(``"iris"``)`` ` `sns.scatterplot(x ``=` `iris.sepal_length,``                ``y ``=` `iris.sepal_width,``                ``hue ``=` `iris.species,``                ``style ``=` `iris.species)`

Output: ## Seaborn.lineplot()

Scatter plots are highly effective, but there is no universally optimal type of visualization. For certain datasets, you may want to consider changes as a function of time in one variable, or as a similarly continuous variable. In this case, drawing a line-plot is a better option.

Syntax :

`seaborn.lineplot(x=None, y=None, data=None, **kwargs)`

Parameters :

ParameterValueUse
x, ynumericInput data variables
hue, size, stylename in data; optionalGrouping variable that will produce elements with different colors.
palettename, list, or dict; optionalColors to use for the different levels of the hue variable.
hue_orderlist; optionalSpecified order for the appearance of the hue variable levels.
hue_normtuple or Normalize object; optionalNormalization in data units for colormap applied to the hue variable when it is numeric.
sizeslist, dict, or tuple; optionaldetermines the size of each point in the plot.
size_orderlist; optionalSpecified order for appearance of the size variable levels
size_normtuple or Normalize object; optionalNormalization in data units for scaling plot objects when the size variable is numeric.
markers, dashesboolean, list, or dictionary; optionalobject determining the shape of marker for each data points.
style_orderlist; optionalSpecified order for appearance of the style variable levels
unitslong_form_varGrouping variable identifying sampling units. When used, a separate line with correct terminology will be drawn for each unit but no legend entry will be inserted. Useful for displaying experimental replicate distribution when exact identities are not necessary.
estimatorname of pandas method or callable or None; optionalMethod for aggregating the vector y at the same x point through multiple observations. If None, all observations will be drawn.
ciint or “sd” or None; optionalSize of the confidence interval to be drawn when aggregating with an estimator. “sd” means drawing a standard deviation.
n_bootint; optional>Number of bootstraps to use for confidence interval measurement.
seedint, numpy.random.Generator, or numpy.random.RandomState; optionalSeed or random number generator for reproducible bootstrapping.
sortbool; optionalis True, sorts the data.
err_style“band” or “bars”; optionalEither using translucent error bands to display the confidence intervals or discrete error bars.
err_kwsdict of keyword argumentsAdditional paramters to control the aesthetics of the error bars.
legend“brief”, “full”, or False; optionalIf “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values. If “full”, every group will get an entry in the legend. If False, no legend data is added and no legend is drawn.
axmatplotlib axes; optionalAxes object in which the plot is to be drawn.
kwargskey, value pairingsOther keyword arguments are passed through to the underlying plotting function.

Example 1: Basic visualization of “fmri” dataset using lineplot()

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=` `'whitegrid'``)``fmri ``=` `sns.load_dataset(``"fmri"``)`` ` `sns.lineplot(x ``=``"timepoint"``,``             ``y ``=``"signal"``,``             ``data ``=` `fmri)`

Output : Example 2: Grouping data points on the basis of category, here as region and event.

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=` `'whitegrid'``)``fmri ``=` `sns.load_dataset(``"fmri"``)`` ` `sns.lineplot(x ``=``"timepoint"``,``             ``y ``=``"signal"``,``             ``hue ``=``"region"``,``             ``style ``=``"event"``,``             ``data ``=` `fmri)`

Output : Example 3: A complex plot visualizing “dots” dataset, to show the power of seaborn. Here, in this example quantitative color mapping is used.

 `import` `seaborn as sns`` ` ` ` `sns.``set``(style ``=` `'whitegrid'``)``dots ``=` `sns.load_dataset(``"dots"``).query(``"align == 'dots'"``)`` ` `sns.lineplot(x ``=``"time"``, ``             ``y ``=``"firing_rate"``,``             ``hue ``=``"coherence"``,``             ``style ``=``"choice"``,``             ``data ``=` `dots)`

Output : Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up