If you currently use Matplotlib or are just starting to learn data vizualization with Python, Seaborn is a great library to try. It offers many features that simplify your daily routines and create beautiful charts. In this article, we will learn how to get started with the seaborn plotting library.
The first step is to install the seaborn library, we can do this with the following command.
pip install seaborn
Let's start with a simple example of how to plot in seaborn, then we can move on to more. In the example below, we will do two interesting things.
We will use the load_dataset
method to pull in built in data from the seaborn library.
Then, we will use the relplot
which creates a basic relation plot. In our case, we have two continous variables, so we will be using a scatter plot (more info on this later). Then, we will split the details by time
using the col
attribute. This will create two scatter plots. Finally, we also apply some styling to the observations to see if a person is a smoker or not.
Don't worry about understanding all the details, just see the basic flow which is:
# Import seaborn
import seaborn as sns
# Load an example dataset
tips = sns.load_dataset("tips")
# Create a visualization
sns.relplot(
data=tips,
x="total_bill", y="tip", col="time",
hue="smoker", style="smoker", size="size",
)