Reputation: 1176
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:
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?
Upvotes: 3
Views: 545
Reputation: 153460
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))
Upvotes: 4