Seaborn

Seaborn is a high-level interface built on top of the Matplotlib. It provides beautiful design styles and color palettes to make more attractive graphs.

To install seaborn type the below command in the terminal.

pip install seaborn

Seaborn is built on the top of Matplotlib, therefore it can be used with the Matplotlib as well. Using both Matplotlib and Seaborn together is a very simple process. We just have to invoke the Seaborn Plotting function as normal, and then we can use Matplotlib’s customization function.

Note: Seaborn comes loaded with dataset such as tips, iris, etc. but for the sake of this tutorial we will use Pandas for loading these datasets.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
 
# reading the database
data = pd.read_csv("tips.csv")
 
# draw lineplot
sns.lineplot(x="sex", y="total_bill", data=data)
 
# setting the title using Matplotlib
plt.title('Title using Matplotlib Function')
 
plt.show()


Output:

Scatter Plot

Scatter plot is plotted using the scatterplot() method. This is similar to Matplotlib, but additional argument data is required.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
# reading the database
data = pd.read_csv("tips.csv")
 
sns.scatterplot(x='day', y='tip', data=data,)
plt.show()


Output:

You will find that while using Matplotlib it will a lot difficult if you want to color each point of this plot according to the sex. But in scatter plot it can be done with the help of hue argument.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
# reading the database
data = pd.read_csv("tips.csv")
 
sns.scatterplot(x='day', y='tip', data=data,
               hue='sex')
plt.show()


Output:

Line Plot

Line Plot in Seaborn plotted using the lineplot() method.  In this, we can pass only the data argument also.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
 
# reading the database
data = pd.read_csv("tips.csv")
 
sns.lineplot(x='day', y='tip', data=data)
plt.show()


Output:

Example 2:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
 
# reading the database
data = pd.read_csv("tips.csv")
 
# using only data attribute
sns.lineplot(data=data.drop(['total_bill'], axis=1))
plt.show()


Output:

Bar Plot

Bar Plot in Seaborn can be created using the barplot() method.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
 
# reading the database
data = pd.read_csv("tips.csv")
 
sns.barplot(x='day',y='tip', data=data,
            hue='sex')
 
plt.show()


Output:

Histogram

The histogram in Seaborn can be plotted using the histplot() function.

Example:

Python3




# importing packages
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
 
 
# reading the database
data = pd.read_csv("tips.csv")
 
sns.histplot(x='total_bill', data=data, kde=True, hue='sex')
 
plt.show()


Output:

After going through all these plots you must have noticed that customizing plots using Seaborn is a lot more easier than using Matplotlib. And it is also built over matplotlib then we can also use matplotlib functions while using Seaborn.

Note: For complete Seaborn Tutorial, refer Python Seaborn Tutorial

Data Visualization with Python

In today’s world, a lot of data is being generated on a daily basis. And sometimes to analyze this data for certain trends, patterns may become difficult if the data is in its raw format. To overcome this data visualization comes into play. Data visualization provides a good, organized pictorial representation of the data which makes it easier to understand, observe, analyze. In this tutorial, we will discuss how to visualize data using Python.

Python provides various libraries that come with different features for visualizing data. All these libraries come with different features and can support various types of graphs. In this tutorial, we will be discussing four such libraries.

  • Matplotlib
  • Seaborn
  • Bokeh
  • Plotly

We will discuss these libraries one by one and will plot some most commonly used graphs. 

Note: If you want to learn in-depth information about these libraries you can follow their complete tutorial.

Before diving into these libraries, at first, we will need a database to plot the data. We will be using the tips database for this complete tutorial. Let’s discuss see a brief about this database.

Similar Reads

Database Used

Tips Database...

Matplotlib

...

Seaborn

Matplotlib is an easy-to-use, low-level data visualization library that is built on NumPy arrays. It consists of various plots like scatter plot, line plot, histogram, etc. Matplotlib provides a lot of flexibility....

Bokeh

...

Plotly

...

Conclusion

...