Q:

Value error when plotting list in list with matplotlib

I'm trying to plot lists in list where x axis is one list and y is a number of lists that are plotted as different lines.
My code can plot lists in list but only as long as the lists have same dimension. For example if I were to plot following it would work
x = np.array(["00:00:02.56","00:00:05.12","00:00:07.68"])
y = np.array([[1171.1,878.1,954.6],[806.7,870.4,1171.1],[954.6,870.4,954.6]])

But if y has one more list ie 4 like below
y = np.array([[1171.1,878.1,954.6],[806.7,870.4,1171.1],[954.6,870.4,954.6],[959.6,980.4,999.6]])

Then I will bet a Value error "ValueError: x and y must have same first dimension"
Error looks like this:
Traceback (most recent call last):
  File "./list_in_list.py", line 137, in <module>
    if __name__ == "__main__": main()
  File "./list_in_list.py", line 26, in main
    multiplot()
  File "./list_in_list.py", line 131, in multiplot
    plt.plot(x,[pt[i] for pt in y],label = 'id %s'%i)
  File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 3154, in plot
    ret = ax.plot(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 1814, in inner
    return func(ax, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_axes.py", line 1424, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 386, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 364, in _plot_args
    x, y = self._xy_from_xy(x, y)
  File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 223, in _xy_from_xy
    raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

My code looks like this
#!/usr/bin/python3

import matplotlib.pyplot as plt
import numpy as np
import datetime

x = np.array(["00:00:02.56","00:00:05.12","00:00:07.68"])
y = np.array([[1171.1,878.1,954.6],[806.7,870.4,1171.1],[954.6,870.4,954.6],[959.6,980.4,999.6]])

x = [datetime.datetime.strptime(elem, '%H:%M:%S.%f') for elem in x]

plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")

for i in range(len(y)):
    plt.plot(x,[pt[i] for pt in y],label = 'id %s'%i)
plt.legend()
plt.show()

How do I plot y in one plot regardless of how many lists y contains.

A:

The plotting loop does not make much sense to me.
Instead try to simply plot each row of y like so
for i, pt in enumerate(y):
    plt.plot(x,pt,label = 'id %s'%i)

