将包含元组的列表绘制到图形

时间:2019-04-16 16:01:24

标签: python plot sage

我有一个元组列表,例如

[("name1",0.05),("name2",0.034),("name3",0.03)....] 

我想用

用这些点的线画一个图
y0 = 0.05
y1 = 0.034 

x0 = "name1"
x1 = "name2" 

以此类推。

我将如何在python / sage中执行此操作?

1 个答案:

答案 0 :(得分:0)

import matplotlib.pyplot as plt
import numpy as np

x = np.array([0,1,2,3])
y = np.array([20,21,22,23])
my_xticks = ['John','Arnold','Mavis','Matt']
plt.xticks(x, my_xticks)
plt.plot(x, y)
plt.show()

对我有很大帮助