Relational plots in Seaborn - Part II
Last Updated :
29 Jul, 2021
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
Python3
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".
Python3
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".
Python3
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 :
Parameter | Value | Use |
---|
x, y | numeric | Input data variables |
data | Dataframe | Dataset that is being used. |
hue, size, style | name in data; optional | Grouping variable that will produce elements with different colors. |
palette | name, list, or dict; optional | Colors to use for the different levels of the hue variable. |
hue_order | list; optional | Specified order for the appearance of the hue variable levels. |
hue_norm | tuple or Normalize object; optional | Normalization in data units for colormap applied to the hue variable when it is numeric. |
sizes | list, dict, or tuple; optional | determines the size of each point in the plot. |
size_order | list; optional | Specified order for appearance of the size variable levels |
size_norm | tuple or Normalize object; optional | Normalization in data units for scaling plot objects when the size variable is numeric. |
markers | boolean, list, or dictionary; optional | object determining the shape of marker for each data points. |
style_order | list; optional | Specified order for appearance of the style variable levels |
alpha | float | proportional opacity of the points. |
legend | “brief”, “full”, or False; optional | If “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. |
ax | matplotlib axes; optional | Axes object in which the plot is to be drawn. |
kwargs | key, value pairings | Other 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.
Python3
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.
Python3
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 :
Parameter | Value | Use |
---|
x, y | numeric | Input data variables |
data | Dataframe | Dataset that is being used. |
hue, size, style | name in data; optional | Grouping variable that will produce elements with different colors. |
palette | name, list, or dict; optional | Colors to use for the different levels of the hue variable. |
hue_order | list; optional | Specified order for the appearance of the hue variable levels. |
hue_norm | tuple or Normalize object; optional | Normalization in data units for colormap applied to the hue variable when it is numeric. |
sizes | list, dict, or tuple; optional | determines the size of each point in the plot. |
size_order | list; optional | Specified order for appearance of the size variable levels |
size_norm | tuple or Normalize object; optional | Normalization in data units for scaling plot objects when the size variable is numeric. |
markers, dashes | boolean, list, or dictionary; optional | object determining the shape of marker for each data points. |
style_order | list; optional | Specified order for appearance of the style variable levels |
units | long_form_var | Grouping 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. |
estimator | name of pandas method or callable or None; optional | Method for aggregating the vector y at the same x point through multiple observations. If None, all observations will be drawn. |
ci | int or "sd" or None; optional | Size of the confidence interval to be drawn when aggregating with an estimator. "sd" means drawing a standard deviation. |
n_boot | int; optional> | Number of bootstraps to use for confidence interval measurement. |
seed | int, numpy.random.Generator, or numpy.random.RandomState; optional | Seed or random number generator for reproducible bootstrapping. |
sort | bool; optional | is True, sorts the data. |
err_style | "band" or "bars"; optional | Either using translucent error bands to display the confidence intervals or discrete error bars. |
err_kws | dict of keyword arguments | Additional parameters to control the aesthetics of the error bars. |
legend | “brief”, “full”, or False; optional | If “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. |
ax | matplotlib axes; optional | Axes object in which the plot is to be drawn. |
kwargs | key, value pairings | Other keyword arguments are passed through to the underlying plotting function. |
Example 1: Basic visualization of "fmri" dataset using lineplot()
Python3
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.
Python3
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.
Python3
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 :
Similar Reads
Partial Order Relation on a Set
A relation is a subset of the cartesian product of a set with another set. A relation contains ordered pairs of elements of the set it is defined on. What is a Partial Order Relation? A relation R on a set A is called a partial order relation if it is Reflexive Relation: (a, a) â R â a â A, i.e. aRa
15 min read
Functional Dependency and Attribute Closure
Functional dependency and attribute closure are essential for maintaining data integrity and building effective, organized, and normalized databases.Functional DependencyA functional dependency A->B in a relation holds if two tuples having the same value of attribute A must have the same value fo
5 min read
Prepositional Inference in Artificial Intelligence
Let's start with quantifiers that are universal. Assume we have in our knowledge base the conventional folklore axiom that All Greedy Kings Are Bad: \forall x \operatorname{King}(x) \wedge \operatorname{Greed} y(x) \Rightarrow \operatorname{Evil}(x) Then it appears that inferring any of the followin
3 min read
Discrete Mathematics Tutorial
Discrete Mathematics is a branch of mathematics that is concerned with "discrete" mathematical structures instead of "continuous". Discrete mathematical structures include objects with distinct values like graphs, integers, logic-based statements, etc. In this tutorial, we have covered all the topic
3 min read
Interesting Facts about DBMS
The amount of information we are surrounded with is literally exploding every single day and there is an immediate need to organise all these data. Database Management System (DBMS) extract information from millions of facts or data stored in a database. As the need for maintenance increased the dem
3 min read
Introduction to Ontologies
Ontologies are a powerful tool for organizing and understanding information in a structured way. They provide a clear framework for defining the relationships between different concepts, making it easier to share and analyze data across various fields. This article will explore what ontologies are,
3 min read
Composition of Relations
Composition of Relations is a mathematical concept that links elements across different sets by combining multiple relations. This powerful tool is fundamental in fields like graph theory, function composition, and system modeling, enabling the exploration of complex connections and relationships wi
13 min read
Degree of Relations in DBMS
We are living in a world where every entity has relationships with one other whether a living or non-living being. For example, you are a single entity but you share different relations with your family and friends. Even within a family, you are the son of your father at the same time you are also a
4 min read
Database Management Systems | Set 6
Following questions have been asked in GATE 2009 CS exam. 1) Consider two transactions T1 and T2, and four schedules S1, S2, S3, S4 of T1 and T2 as given below: T1 = R1[X] W1[X] W1[Y] T2 = R2[X] R2[Y] W2[Y] S1 = R1[X] R2[X] R2[Y] W1[X] W1[Y] W2[Y] S2 = R1[X] R2[X] R2[Y] W1[X] W2[Y] W1[Y] S3 = R1[X]
4 min read
Database Management Systems | Set 10
Following questions have been asked in GATE CS 2005 exam. 1) Let r be a relation instance with schema R = (A, B, C, D). We define r1 = 'select A,B,C from r' and r2 = 'select A, D from r'. Let s = r1 * r2 where * denotes natural join. Given that the decomposition of r into r1 and r2 is lossy, which o
3 min read