By default pandas.DataFrame.plot() using the subplots option doesn't seem to make it easy to plot a ylabel per subplot. I am trying to plot a pandas dataframe having a subplot per column in the dataframe. Code so far that doesn't work:
fig = plt.figure(figsize=(10,10))
ax = plt.gca()
df.plot(y=vars, ax=ax, subplots=True, layout=(3,1), sharex=True, legend=False,)
ax.set_ylabel = ['y','x', 'z']
But this doesn't plot any labels at all.
You can manually create the subplots with matplotlib, and then plot the dataframes on a specific subplot using the ax keyword. For example for 4 subplots (2x2): import matplotlib. pyplot as plt fig, axes = plt.
Pandas has a tight integration with Matplotlib. You can plot data directly from your DataFrame using the plot() method. To plot multiple data columns in single frame we simply have to pass the list of columns to the y argument of the plot function.
You can set y label on each ax separately.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# data
df = pd.DataFrame(np.random.randn(100,3), columns=list('ABC'))
# plot
axes = df.plot(figsize=(10, 10), subplots=True, sharex=True, legend=False)
axes[0].set_ylabel('yA')
axes[1].set_ylabel('yB')
axes[2].set_ylabel('yC')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With