Plot multiple columns of dataframe in multiple plots (Python)

Tags: ,

i want to plot multiple columns from a dataframe in multiple plots.

My code looks like this:

fig, axs = plt.subplots(6)

The error i get is:

ValueError: x and y must have same first dimension, but have shapes (1995,) and (3, 1995)

I know x and y need to have the same shape, but how can i solve this problem here? My entire data is within one dataframe and should have the same shape. Is it possible to pass a list as a y value and change the shape?

My data looks like this: enter image description here

aapl = "EOD/AAPL - Adj_Close"
msft = "EOD/MSFT - Adj_Close"
fb = "EOD/FB - Adj_Close"
amzn = "EOD/AMZN - Adj_Close"
nflx = "EOD/NFLX - Adj_Close"
googl = "EOD/GOOGL - Adj_Close"


I am not sure what output you are expecting, but the following code can be used to resolve the above error. I have matched the stocks for the sample data, but the column names are different.

import matplotlib.pyplot as plt
import pandas as pd

fig, axes = plt.subplots(6,1, figsize=(12,9))
axes[0].plot([data.Date,data.Date,data.Date],[data['Adj Close_AAPL'],data['High_AAPL'],data['Low_AAPL']])
axes[1].plot([data.Date,data.Date,data.Date],[data['Adj Close_MSFT'],data['High_MSFT'],data['Low_MSFT']])
axes[2].plot([data.Date,data.Date,data.Date],[data['Adj Close_FB'],data['High_FB'],data['Low_FB']])
axes[3].plot([data.Date,data.Date,data.Date],[data['Adj Close_AMZN'],data['High_AMZN'],data['Low_AMZN']])
axes[4].plot([data.Date,data.Date,data.Date],[data['Adj Close_NFLX'],data['High_NFLX'],data['Low_NFLX']])
axes[5].plot([data.Date,data.Date,data.Date],[data['Adj Close_GOOGL'],data['High_GOOGL'],data['Low_GOOGL']])

enter image description here

Source: stackoverflow