0

Say I have two lists

a=[[0,2,4]]
b=[[3,5,7]]

when I plot using matplotlib I know I can just get rid of the square brackets, i.e.

plt.plot([0,2,4], [3,5,7])

but what if I had a large list listed as a variable, say x, how to I plot it knowing I would I have to deal with double square brackets?

9
  • 3
    Python 5?! What year is this? Commented Dec 22, 2016 at 21:14
  • Python 5 ? Damn, I still use old 3.5. Commented Dec 22, 2016 at 21:14
  • Haha, I just couldn't find a suitable title that wasnt taken sorry Commented Dec 22, 2016 at 21:15
  • 3
    Joking aside, it's not clear what you're asking. The answer is probably plot(*x), though. You know the square brackets are the indication of a list right? You don't "get rid of" them anywhere. Commented Dec 22, 2016 at 21:15
  • square brackets are only information for you that you have list (or N-dimensional list) and not single value. You may need to use index - ie. some_list[0] Commented Dec 22, 2016 at 21:16

1 Answer 1

3

From my understanding of the question, the lists are structured like [[1, 2, 3]].

This is an example of a two-dimensional list - albeit it a very useless one. If one consider another two dimensional list: [[1, 2], [3, 4]] The two lists inside the outer list can be treated as items of that list. ie:

a = [[1, 2],
     [3, 4]]

a[0] --> [1, 2]
a[1] --> [3. 4]

So in your example, the simplest way to turn the 2 dimensional list into a one dimensional list is simply take the first element of the list (because the first element is actually the useful list).

a = [[1, 2, 3]]
b = [[4, 5, 6]]

plt.plot(a[0], b[0])
plt.plot([1, 2, 3], [4, 5, 6])  # is the same as above
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.