Commits

Anonymous committed d5d619b

added function to help index to color conversions

Comments (0)

Files changed (1)

Code/Python/Display/PyCADisplay.py

     plt.xticks([])
     plt.yticks([])
     plt.draw()
+
+def SampleCMap(nSamples, cmap=matplotlib.cm.jet):
+    """
+    Evenly sample a colormap.  Used to create easy index-to-color
+    mappings.
+    """
+    norm = matplotlib.colors.Normalize(vmin=0, vmax=nSamples)
+    sm = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap)
+    colors = sm.to_rgba(np.arange(nSamples))
+    return colors
+
+