Member-only story
Data Visualization with Matplotlib, Seaborn, and Pandas
Kind of the same, but also different
Seaborn is based on Matplotlib, and Pandas visualizations are Matplotlib objects, but even though they’re using the same backend, the way we plot our charts with each can be quite unique.
This article will explore different bar charts to compare the usability, advantages, and disadvantages of Matplotlib, Pandas, and Seaborn for data visualization.
We’ll start by defining some dummy data and importing the needed libraries.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
import numpy as npdata = {'label':['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'],
'percent':[.1, .2, .3, .4, .5, .6, .7, .8, .9, 1],
'remaining':[.9, .8, .7, .6, .5, .4, .3, .2, .1, 0],
}df = pd.DataFrame(data)
We’ll create a Matplotlib figure with three subplots and then plot three bar charts, one with Matplotlib, one with Pandas, and one with Seaborn.
f, (ax1, ax2, ax3) = plt.subplots(3, figsize=(12,8))# matplotlib
ax1.bar(df.label, df.percent)# pandas
df.plot(x='label', y='percent', kind='bar', ax=ax2)