Professional Documents
Culture Documents
● The function of the figure module used to add axes to the figure is add_axes().
● Parameters:
○ rect: [left, bottom, width, and height] (The parameter is used to set new dimensions of the figure. It
takes values in float also.)
○ Projection: None, ‘aitoff’, ‘hammer’, ‘lambert’, ‘mollweide’, ‘polar’, ‘rectilinear’. By default, the project is
None which results in ‘rectilinear’ projection.
○ Polar: bool (By default, polar is set to False. If we set it to True, axes results in ‘polar’ projection.)
● Parameters:
○ Fig : Figure to place axis in. Defaults to current figure. (Figure, optional)
subplot2grid()
Using seaborn: FacetGrid()
● Seaborn also provides some functions for plotting multiple plots
● FacetGrid class helps in visualizing distribution of one variable as well as the relationship between
multiple variables separately within subsets of your dataset using multiple panels.
● Parameters
○ Data: Dataframe
○ Row, col: strings (variables that define subsets of the data which will be drawn on separate facets in the grid.
The column should be categorical )
Using seaborn: FacetGrid()
Overview of seaborn plots
Seaborn plots
● We can classify all the functions offered by Seaborn into 2 categories:
○ Axes-level functions
○ Figure-level functions
● Axes-level functions are the easiest to understand. They operate on a single Matplotlib "Axes" object
and are intended to be "replacements" of the individual plot types provided by Matplotlib. When
used, they only control one Axes object, and not the entire figure.
● The figure-level functions take control of the entire Matplotlib "Figure" object. They create subplots
within your figure as they see fit. For each subplot, they delegate work to the Axes-level functions.
Figure level functions
○ The process of understanding how the variables in the dataset relate each other and their
relationships are termed as Statistical analysis
○ To draw the relational plots seaborn provides three functions. These are:
■ relplot()
■ scatterplot()
■ lineplot()
relplot()
● Syntax: seaborn.relplot(x=None, y=None, data=None, kind=‘scatter’, **kwargs)
● Parameters:
● 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.
● Parameters
○ hue: Grouping variable that will produce points with different colors. Can be either categorical or numeric.
Scatter plot 1
.
Scatter plot 2
.
Scatter plot 2
.
Scatter plot 3
.
Scatter plot 4
.
Line plot
● 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. It is plotted using the lineplot() method.
● With 2D histograms, we can expand that definition to two variables (bivariate distributions).
○ A more specialized approach can be used if one of the main variable is categorical which
means such variables that take on a fixed and limited number of possible values.
○ Categorical Scatter plots: These show individual points divided by categories. Eg; strip and
swarm plot
○ Categorical Distribution plots: They aggregate the points for each category and show their
overall distribution and various statistics. Eg: box and violin plot
○ Categorical Estimate plots: They also aggregate the points for each category, but focus on
showing a handful of statistics (sum, count etc.) rather than the distribution. Eg; point and bar
plot
Strip plot
● It basically creates a scatter plot based on the
category. It is created using the stripplot() method.
● The x-axis is often some measure of time but can be any variable with groupings. The y-axis is a
variable that defines the categories in the data.
● Each rectangle is the same size. The rectangles are colored to show the magnitude of a third
variable.
● Heat map has the ability to derive valuable insights from vast datasets
Heat map
● Heatmaps in Seaborn can be plotted by using the seaborn.heatmap() function.
○ Vmin, vmax: values to anchor the colormap, otherwise they are inferred from the data