3

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.

1
  • If you change it to data = [[4,3,4,0],[2,3,0,0],[5,6,4,5]], does the result look right? Commented Oct 21, 2016 at 19:55

1 Answer 1

4

What about just doing

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

?

Sign up to request clarification or add additional context in comments.

1 Comment

Too easy... Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.