def makeLegendInOwnFigure( Jdict, names = ['stoch', 'sampler', 'memo', 'delete,merge', 'birth,delete,merge', 'Sticky=0', 'Sticky=50'], ): ''' Create legend for trace plots, in separate matplotlib figure. ''' # Split up each name into original name (key in Jdict) and legend name origNames = list() legendNames = list() for name in names: if name.count(":") > 0: fields = name.split(":") origNames.append(fields[0]) legendNames.append(fields[1]) else: origNames.append(name) legendNames.append(name) # Build job dict with one entry for each of the specified names J2 = OrderedDict() for name in origNames: Jmatch = getSubsetByName(Jdict, name, keepName=1) if len(Jmatch.keys()) == 0: raise ValueError("Cannot find key %s in provided job path dict" % ( name)) firstkey = Jmatch.keys()[0] Jsingle = dict() Jsingle[name + firstkey] = Jmatch[firstkey] J2.update(Jsingle) # Make trace plot with these jobs only PlotUtil.plotHammingDist(J2, loc=None, xscale='log') # Grab current axes of this trace plot axH = PlotUtil.pylab.gca(); # Set all line handles to wide, solid lines lineHandles, lineLabels = axH.get_legend_handles_labels() for ii in range(len(lineHandles)): lineHandles[ii].set_linewidth(6) lineHandles[ii].set_linestyle('-') if names[ii].count('Sticky'): lineHandles[ii].set_color('k') lineHandles[ii].set_linewidth(3) if names[ii].count('Sticky=0'): lineHandles[ii].set_linestyle('--') # Remove lines from the plot entirely, so its just the legend axH.axis('off') for ii in range(len(axH.lines)): axH.lines.pop() # Show the legend axH.legend(lineHandles, legendNames)