[英]How to plot list of tuples in python?
如何使用matplotlib模塊在python中繪制元組列表? 元組列表
[(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)]
在元組中,第一個值表示反應數,第二個值表示靈敏度。
怎么樣:
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()
我假設你想要x軸上的反應數和y軸上的靈敏度。 在這種情況下,您必須轉置列表:
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.