What are some of the features that make Seaborn different from Matplotlib?


#1

Question

What are some of the features that make Seaborn different from Matplotlib?

Answer

Seaborn is a module for Data Visualization that builds upon Matplotlib, so many of the underlying functionality of Seaborn are from Matplotlib. If you know Matplotlib, you can quickly learn Seaborn.

The purpose of Seaborn is to provide some important improvements and extra features on top of Matplotlib.

One very important and useful improvement is the more visually appealing plots, which is clear when you see how plots appear using both libraries.

Another important improvement is the concise syntax that Seaborn provides. Take for example, drawing a bar plot.

In Seaborn, it is simply:

df = pd.read_csv("information.csv")

sns.barplot(
  data = df,
  x = "X Label",
  y = "Y Label"
)

In Matplotlib:

df = pd.read_csv("information.csv")

ax = plt.subplot()

plt.bar(range(len(df)), df["Y Label"])

ax.set_xticks(range(len(df)))
ax.set_xticklabels(df["X Label"])

plt.xlabel("X Label")
plt.ylabel("Y Label")

As we can see, Seaborn can be much more concise.

In addition, Seaborn further improves from Matplotlib because of its ability to better understand and utilize Pandas DataFrames directly, as also seen in the example above, where it knew to use the columns "X Label" and "Y Label" from the dataframe df.

Last, but not least, Seaborn can more easily work with Pandas DataFrames by aggregating the rows of data, as you’ll soon see as you proceed to the later exercises in the lesson.