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: 

Relational plots in Seaborn – Part II

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: 
 

Similar Reads

Seaborn.scatterplot()

...

Seaborn.lineplot()

...

Contact Us