3

I have a dataframe I want to plot.

The dataframe has five columns, one being used as the x-axis, and the other four columns as the y-axis values.

The current code in use is :

ax = plt.gca()

df.plot(kind='line',x='Vertical',y='Gr', color = 'brown', ax=ax)
df.plot(kind='line',x='Vertical',y='R', color='red', ax=ax)
df.plot(kind='line',x='Vertical',y='B', color='blue', ax=ax)
df.plot(kind='line',x='Vertical',y='Gb', color='cyan', ax=ax)

plt.show()

This outputs 4 graphs, all in the same axes. However, this makes the graphs not very readable, as the graphs can be very noisy and they overlap with each other a lot.

For example:

enter image description here

Is there a way to separate the four graphs into different axes so that I can read each graph separately, other than repeating the entire code four times?

1 Answer 1

4

Try:

fig, ax = plt.subplots(2,2, figsize=(10,8))

df.plot(kind='line',x='Vertical',y='Gr', color = 'brown', ax=ax[0,0])
df.plot(kind='line',x='Vertical',y='R', color='red', ax=ax[0,1])
df.plot(kind='line',x='Vertical',y='B', color='blue', ax=ax[1,0])
df.plot(kind='line',x='Vertical',y='Gb', color='cyan', ax=ax[1,1])

plt.show()

OR

df[['Gr','R','B','Gb']].plot(subplots=True, figsize=(10,8))
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.