Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot list of lists (which different length) in a plot in python

Tags:

python

plot

numpy

I have a list of lists, each of these internal lists has a different length, and I would like to show them in a graph.

They would look like this:

data = [[4,3,4],[2,3],[5,6,4,5]]

for each of these, I would like to plot them against there index (x-axis), so for instance, for the first list: (0,4),(1,3),(2,4)

If my lists would have been the same length, I would have converted them to a numpy array and just plotted them:

data_np = np.vstack(data)
plot_data_np = np.transpose(data_np)
plt.plot(plot_data_np)

However, there is this length issue... In a hopeful attempt I tried:

plt.plot(data)

But alas.

like image 736
dorien Avatar asked Jul 18 '26 23:07

dorien


1 Answers

What about just doing

data = [[4,3,4],[2,3],[5,6,4,5]]
for d in data:
    plt.plot(d)

?

like image 152
jmd_dk Avatar answered Jul 21 '26 14:07

jmd_dk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!