0

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

My code looks like this:

fig, axs = plt.subplots(6)
axs[0].plot(data.Date,[data[aapl],data['High_'+aapl],data['Low_'+aapl]])
axs[1].plot(data.Date,[data[msft],data['High_'+msft],data['Low_'+msft]])
axs[2].plot(data.Date,[data[fb],data['High_'+fb],data['Low_'+fb]])
axs[3].plot(data.Date,[data[amzn],data['High_'+amzn],data['Low_'+amzn]])
axs[4].plot(data.Date,[data[nflx],data['High_'+nflx],data['Low_'+nflx]])
axs[5].plot(data.Date,[data[googl],data['High_'+googl],data['Low_'+googl]])

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"
1
  • Can you show how your data looks? Commented Jan 24, 2021 at 13:06

1 Answer 1

1

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']])

plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.