简体   繁体   English

如何在python中绘制元组列表?

[英]How to plot list of tuples in python?

How to plot a list of tuples in the python using matplotlib module? 如何使用matplotlib模块在python中绘制元组列表? 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. 在元组中,第一个值表示反应数,第二个值表示灵敏度。

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()

I assume you want reaction number on the x axis and sensitivity on the y axis. 我假设你想要x轴上的反应数和y轴上的灵敏度。 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM