使用matplot lib绘制图

时间:2019-10-12 18:05:57

标签: python-3.x matplotlib

我有一个类似的列表:    [[5,1.1066720079718957],[10,1.075297753414681],[15,1.0958222358382397],[20,1.092081009894558],[25,1.0968130408510393]]

我正在尝试使用matplotlib进行绘图 其中值5,10,15,20,25在x轴上,在y轴上为1.1066720079718957,1.075297753414681,1.0958222358382397,1.092081009894558,1.0968130408510393

我无法在几行中做到这一点。

1 个答案:

答案 0 :(得分:1)

import matplotlib.pyplot as plt

data = [[5, 1.1066720079718957], [10, 1.075297753414681], [15, 1.0958222358382397], [20, 1.092081009894558], [25, 1.0968130408510393]]

plt.plot([i[0] for i in data], [i[1] for i in data])
plt.show()

如果您正在使用嵌套列表和列表理解,也许这两个链接也将很有用

  1. Nested lists python
  2. What does "list comprehension" mean? How does it work and how can I use it?