'How to plot Dataframe for many rows?
I have a dataset where each row plots an ECG, with 50k rows, 181 columns and has 4 classes, represented in the last column (0, 1, 2, 3).
So, I need to "convert" each row for images plotting each one, but I only know to separate according to the values of the last column and plot each one.
Plotting this manually and will take a lot of time to finish,is there a way to plot a considered number of images for each class?
I'm using Python for this work.
Solution 1:[1]
You can do this by using the method subplots() using Matplotlib. Here is an example using a list of lists for the data and then indexing for the axis. Using a pandas pandas you can achieve the same output itering through the columns in the for loop.
Note; if the figure has more the 1 column of axis you have do index it with 2 brackets [col][row]
y_vals = [0, 2, 5, 6, 6, 8]
x_vals = [2 , 4, 6, 8, 10, 12]
x_data = [x_vals for x in range(4)]
y_data = [y_vals for y in range(4)]
fig, ax = plt.subplots(4, figsize=(4, 8))
for i in range(4):
ax[i].plot(x_data[i], y_data[i])
fig, ax2 = plt.subplots(4,4, figsize=(8, 4))
for i in range(4):
for j in range(4):
ax2[i][j].plot(x_data[i], y_data[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 | Jorge Alvarez |