I have a dataset from which I need to plot various, discontinuous, lines. Segments that belong to the same index within the dataset will have the same color. I have used the code provided in this topic as the base but due to the datastructure I have placed it in a loop:
import pylab as pl
from matplotlib import collections as mc
color = ['r','g','b','c','y','k','m']
fig, ax = pl.subplots()
for i in indexset:
lines=mc.LineCollection(data[i],colors=color[i])
ax.addcollection(lines)
For each of the sets of lines, I would like to add a label/legend entry with the corresponding index i. Either a legend box with the index i next to the color of the line and/or the index as text within the graph. I tried adding a label=i argument within the loop, however then only the last index actually shows on the plot. How can I add a label for each index?