VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/relational-plots-in-seaborn-part-i/

โ‡ฑ Relational plots in Seaborn - Part I - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Relational plots in Seaborn - Part I

Last Updated : 21 Jul, 2021

Relational plots are used for visualizing the statistical relationship between the data points. Visualization is necessary because it allows the human to see trends and patterns in the data. The process of understanding how the variables in the dataset relate each other and their relationships are termed as Statistical analysis. 

Seaborn, unlike to matplotlib, also provides some default datasets. In this article, we will be using a default dataset named 'tips'. This dataset gives information about people who had food at some restaurant and whether they left tip for waiters or not, their gender and whether they do smoke or not, and more.

Let us have a look to the dataset.

Output :

 total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

To draw the relational plots seaborn provides three functions. These are:

  • relplot()
  • scatterplot()
  • lineplot()

Seaborn.relplot()

This function provides us the access to some other different axes-level functions which shows the relationships between two variables with semantic mappings of subsets.

Syntax : 

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

Parameters : 


 

ParameterValueUse
x, ynumericInput data variables
DataDataframeDataset that is being used.
hue, size, stylename in data; optionalGrouping variable that will produce elements with different colors.
kindscatter or line; default : scatterdefines the type of plot, either scatterplot() or lineplot()
row, colnames of variables in data; optionalCategorical variables that will determine the faceting of the grid.
col_wrapint; optionalโ€œWrapโ€ the column variable at this width, so that the column facets span multiple rows.
row_order, col_orderlists of strings; optionalOrder to organize the rows and columns of the grid.
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.
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.
heightscalar; optionalHeight (in inches) of each facet.
Aspectscalar; optionalAspect ratio of each facet, i.e. width/height
facet_kwsdict; optionalDictionary of other keyword arguments to pass to FacetGrid.
kwargskey, value pairingsOther keyword arguments are passed through to the underlying plotting function.


 

Example 1: Visualizing the most basic plot to show all the data points in tips dataset.


 

Output :

๐Ÿ‘ Image

Example 2: Grouping data points on the basis of category, here as time.

Output :

๐Ÿ‘ Image

Example 3: using time and sex for determining the facet of the grid.

Output :

๐Ÿ‘ Image

Example 4: using size attribute, we can see data points having different size.

Output :

๐Ÿ‘ Image
Comment