Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas.
Scatterplot can be used with several semantic groupings which can help to understand well in a graph. They can plot two-dimensional graphics that can be enhanced by mapping up to three additional variables while using the semantics of hue, size, and style parameters. All the parameter control visual semantic which are used to identify the different subsets. Using redundant semantics can be helpful for making graphics more accessible.
Syntax: seaborn.scatterplot(x=None, y=None, hue=None, style=None, size=None, data=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, markers=True, style_order=None, x_bins=None, y_bins=None, units=None, estimator=None, ci=95, n_boot=1000, alpha=’auto’, x_jitter=None, y_jitter=None, legend=’brief’, ax=None, **kwargs)
x, y: Input data variables that should be numeric.
data: Dataframe where each column is a variable and each row is an observation.
size: Grouping variable that will produce points with different sizes.
style: Grouping variable that will produce points with different markers.
palette: Grouping variable that will produce points with different markers.
markers: Object determining how to draw the markers for different levels.
alpha: Proportional opacity of the points.
Returns: This method returns the Axes object with the plot drawn onto it.
Creating a Scatter Plot
Let’s visualize of “fmri” dataset using seaborn.scatterplot() function. We will only use the x, y parameters of the function.
Grouping data points on the basis of category, here as region and event.
Basic visualization of “tips” dataset using Scatterplot.
Grouping variables in Seaborn Scatter Plot with different attributes
1. Adding the marker attributes
The circle is used to represent the data point and the default marker here is a blue circle. In the above output, we are seeing the default output for the marker, but we can customize this blue circle with marker attributes.
2. Adding the hue attributes.
It will produce data points with different colors. Hue can be used to group to multiple data variable and show the dependency of the passed data values are to be plotted.
Syntax: seaborn.scatterplot( x, y, data, hue)
In the above example, we can see how the tip and day bill is related to whether it was lunchtime or dinner time. The blue color has represented the Dinner and the orange color represents the Lunch.
Let’s check for a hue = ” day “
3. Adding the style attributes.
Grouping variable that will produce points with different markers. Using style we can generate the scatter grouping variable that will produce points with different markers.
seaborn.scatterplot( x, y, data, style)
4. Adding the palette attributes.
Using the palette we can generate the point with different colors. In this below example we can see the palette can be responsible for a generate the scatter plot with different colormap values.
seaborn.scatterplot( x, y, data, palette=”color_name”)
5. Adding size attributes.
Using size we can generate the point and we can produce points with different sizes.
seaborn.scatterplot( x, y, data, size)
6. Adding legend attributes.
.Using the legend parameter we can turn on (legend=full) and we can also turn off the legend using (legend = False).
If the legend is “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values.
If the legend is “full”, every group will get an entry in the legend.
If False, no legend data is added and no legend is drawn.
Syntax: seaborn.scatterplot( x, y, data, legend=”brief)
7. Adding alpha attributes.
Using alpha we can control proportional opacity of the points. We can decrease and increase the opacity.
Syntax: seaborn.scatterplot( x, y, data, alpha=”0.2″)
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.