这可能很简单,我提前道歉,我找不到我到底要找的东西:)
我有6个整数列表,长度相同。我想在同一个图表上用不同的颜色相互绘制它们,每个图形在图例中都有自己的名称。
基本上,我有
my_lists = [list1, list2, list3, list4, list5, list6]
其中每个列表只是整数。然后我有
legend_names = ["line 1", "line 2", "line 3", "line 4", "line 5", "line 6"]
如何将这两条信息都包含在matplotlib图中?
答案 0 :(得分:2)
import matplotlib.pyplot as plt
import math
my_lists = [[i*math.exp(-x/10.) for x in range(10) ] for i in range(1,7)]
legend_names = ["line 1", "line 2", "line 3", "line 4", "line 5", "line 6"]
for ydata, name in zip(my_lists, legend_names):
plt.plot(ydata, label = name)
plt.legend(loc = 'best')
plt.show()
产量