1

I can plot many subplots from each series of a dataframe in 1 figure like this:

import pandas as pd

NG = [1,2,3,4,5,6,7]
dflist = []

l = [1,2,3,4,5,6]
b = [6,5,4,3,2,1]


for n in NG:
    df = pd.DataFrame(l)
    dflist.append(df)
    df2 = pd.DataFrame(b)
    dflist.append(df2)
    df = pd.concat(dflist, axis = 1)

df.plot(grid = 1, subplots = True, layout = (7,2), sharey = True)

print(df)

enter image description here

How can I combine every second plot? It should look like this:

enter image description here

1 Answer 1

1

If I understand correctly your previous question and this, you're looking for something like this:

import pandas as pd

l = [1,2,3,4,5,6]
b = [6,5,4,3,2,1]

for n in range(7):
    dflist = []
    df = pd.DataFrame(l)
    dflist.append(df)
    df2 = pd.DataFrame(b)
    dflist.append(df2)
    df = pd.concat(dflist, axis = 1)
    ax = subplot(4, 2, n + 1)
    df.plot(ax=ax);

enter image description here

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

2 Comments

I get an (TypeError: 'tuple' object is not callable) with (ax = subplots(4, 2, n + 1)) . Do i need to import Matplotlib? Spyder tells me that subplot is not defined
Ok, it works with matplotlib.pyplot. Yes, that is what I was looking for. Thank you vm :-)

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.