DATA VISUALIZATION IN PANDAS
Although Matplotlib and Seaborn are often the “go to” Python libraries for data visualization, you can also use Pandas for such tasks.
Listing 3.38 displays the contents pandas_viz1.py that illustrates how to render various types of charts and graphs using Pandas and Matplotlib.
LISTING 3.38: pandas_viz1.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.rand(16,3), columns=['X1','X2','X3'])
print("First 5 rows:")
print(df.head())
print()
print("Diff of first 5 rows:")
print(df.diff().head())
print()
# bar chart:
#ax = df.plot.bar()
# horizontal stacked bar chart:
#ax = df.plot.barh(stacked=True)
# vertical stacked bar chart:
ax = df.plot.bar(stacked=True)
# stacked area graph:
#ax = df.plot.area()
# non-stacked area graph:
#ax = df.plot.area(stacked=False)
#plt.show(ax)
Listing 3.38 initializes the DataFrame df with a 16x3 matrix of...