3

How to plot a list of tuples in the python using matplotlib module? List of the tuples

[(155, 16.84749748246271), (158, 13.618280538390644), (38, 13.103707537648402), (53, 10.157244261797375), (156, 6.779897254994966), (119, 6.27045632052444), (159, 4.3453112093858275), (161, 4.028984416275573), (32, 4.026263736663865), (118, 3.437058351914913)]

In tuples first values represents the reaction number and second values represent sensitivity.

2 Answers 2

5

How about:

import matplotlib.pyplot as plt
plt.plot([(155, 16.84749748246271), (158, 13.618280538390644), (38, 13.103707537648402), (53, 10.157244261797375), (156, 6.779897254994966), (119, 6.27045632052444), (159, 4.3453112093858275), (161, 4.028984416275573), (32, 4.026263736663865), (118, 3.437058351914913)])
plt.show()
Sign up to request clarification or add additional context in comments.

1 Comment

The list which I had shown is the result which is sorted in the according to the second value in the list and I want to plot first and second value
1

I assume you want reaction number on the x axis and sensitivity on the y axis. In this case you have to transpose the list:

xs = [x for x, y in data]
ys = [y for x, y in data]

plt.plot(xs, ys)
plt.show()

Comments

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.