'How to plot multiple graphs from file for each 3 columns ? in python
I don't see the strategy to work on it. I have a file, with several columns, each 3 columns represent a graph. The first column are the title and the two others column are x and y.
| "Body" | "x" | "y " | "Skin" | "x" | "y " | "Head" | "x" | "y " |
|---|---|---|---|---|---|---|---|---|
| 0 | 100 | 0 | 100 | 0 | 100 | |||
| 1 | 99 | 0 | 99 | 0 | 98 |
I would like to have multiple graph. I thought that the solution would be to separate the table over 3 but it's not very smart. I didn't find a function in panda or matplotlib. Do you have an idea?
Thank you
Solution 1:[1]
You could iterate over the columns like this:
for i in enumerate(df.columns):
if i%3 == 2:
_title = df.iloc[0,i-2]
x = df.iloc[:,i-1]
y = df.iloc[:,i]
plt.plot(x, y)
plt.show()
Solution 2:[2]
try this:
import matplorlib.pyplot as plt
import pandas
fig, ax = plt.subplots(3,1, figsize=(30,5))
ax.ravel()
for i, axis in enumerate(ax):
sns.lineplot(x=df.iloc[:, 1+3*i], y=df.iloc[:, 2+3*i], ax=axis)
axis.set_title(df.columns[0+3*i])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Florian de Koning |
| Solution 2 | amy989 |
