Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to draw graph using a list of (x,y) pairs instead of using two lists, one of X's and one of Y's. Something like this:

a = [[1,2],[3,3],[4,4],[5,2]]
plt.plot(a, 'ro')

Rather than:

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

Suggestions?

question from:https://stackoverflow.com/questions/2282727/draw-points-using-matplotlib-pyplot-x1-y1-x2-y2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
433 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do something like this:

a=[[1,2],[3,3],[4,4],[5,2]]
plt.plot(*zip(*a))

Unfortunately, you can no longer pass 'ro'. You must pass marker and line style values as keyword parameters:

a=[[1,2],[3,3],[4,4],[5,2]]
plt.plot(*zip(*a), marker='o', color='r', ls='')

The trick I used is unpacking argument lists.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...