620.00 a

Description: In matplotlib library, cover fundamental like concep.

#600#ML_Libraries_and_Implementation#620#Data_visualization#620.00#Matplotlib#620.00 a#Matplotlib_Fundamental

import matplotlib.pyplot as plt
import pandas as pd

# Create dataframe from random numbers
data = pd.DataFrame({'x': range(10), 'y': range(10)})

# Configure subplot size 2x2
fig, axes = plt.subplots(2, 2)

# Transform axes to 1 dimentional array for easy use
axes_flat = axes.flatten()

# Use plot in dataframe corresponding each axis
data.plot(x='x', y='y', ax=axes_flat[0])  # 1st axis
data.plot(x='x', y='y', ax=axes_flat[1], kind='bar')  # 2nd axis
data.plot(x='x', y='y', ax=axes_flat[2], kind='scatter')  # 3rd axis
data.plot(x='x', y='y', ax=axes_flat[3], kind='hist')  # 4th axis

# Visualize graph
plt.show()

Automatically adjust the layout

plt.tight_layout()

Control the labels

#Matplotlib


for ax in axes:
    # y-axis label
    ax.yaxis.label.set_rotation(0)
    ax.yaxis.set_label_coords(-0.5, 0.5)
    # x-tick labels
    ax.xaxis.set_label_position('top')
    ax.set_xticklabels(ax.get_xticklabels(), rotation=0)