Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot list of tuples in python?

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.

like image 315
tushar bommala Avatar asked Feb 16 '26 20:02

tushar bommala


2 Answers

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()
like image 79
U12-Forward Avatar answered Feb 19 '26 09:02

U12-Forward


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()
like image 21
BlackBear Avatar answered Feb 19 '26 09:02

BlackBear



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!