'How can I plot few data sets with one X(time) from Excel file in python
[enter image description here][1]I have an excel data set with 5 columns and 300+ rows(from excel file): and I'm trying to plot an y vs. x plot(line) of [1:] columns while column 0 is 'Time'(0:300+ rows).
Time cycle1 cycle2 cycle 3 cycle4... cycle 15
0 0.5 0.2 0.5 0.4 ... 0.55
1 0.51 0.21 0.52 0.43 ... 0.6
.
.
My code so far doesn't work(plus it's too long and I couldn't find a better way to make it better). I would like your help! Thank you in advance!!
df = pd.read_excel(io.BytesIO(uploaded['Book1.xlsx']))
x = df['Time']
y1 = df['cycle 1']
y2 = df['cycle 2']
y3 = df['cycle 3']
y4 = df['cycle 4']
y5 = df['cycle 5']
y6 = df['cycle 6']
y7 = df['cycle 7']
y8 = df['cycle 8']
y9 = df['cycle 9']
y10 = df['cycle 10']
y11 = df['cycle 11']
y12 = df['cycle 12']
y13 = df['cycle 13']
y14 = df['cycle 14']
y15 = df['cycle 15']
plt.plot(x,y1, y2, y3,y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15 )
plt.show()```
[1]: https://i.stack.imgur.com/QGMZM.png
Solution 1:[1]
Maybe comprehension is what you need here:
[plt.plot(df['Time'], df[f'cycle {i}']) for i in range(1, len(df.columns))]
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 | Ze'ev Ben-Tsvi |
