Matching legend to data