Skip to content Skip to sidebar Skip to footer

Plot Multiple Lines On Subplots With Pandas Df.plot

Is there a way to plot multiple dataframe columns on one plot, with several subplots for the dataframe? E.g. If df has 12 data columns, on subplot 1, plot columns 1-3, subplot 2,

Solution 1:

This is an example of how I do it:

import pandas as pd
import numpy as np
import matplotlib.pyplotas plt

fig, axes = plt.subplots(1, 2)

np.random.seed([3,1415])
df = pd.DataFrame(np.random.randn(100, 6), columns=list('ABCDEF'))
df = df.div(100).add(1.01).cumprod()

df.iloc[:, :3].plot(ax=axes[0])
df.iloc[:, 3:].plot(ax=axes[1])

enter image description here

Post a Comment for "Plot Multiple Lines On Subplots With Pandas Df.plot"