from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0.486275, 0.47451, 0.513725],
[0.486275, 0.47451, 0.513725],
[0.47451, 0.552941, 0.52549],
[0.462745, 0.607843, 0.537255],
[0.45098, 0.627451, 0.54902],
[0.439216, 0.607843, 0.560784],
[0.427451, 0.552941, 0.572549],
[0.415686, 0.47451, 0.584314],
[0.403922, 0.380392, 0.596078],
[0.392157, 0.282353, 0.607843],
[0.380392, 0.203922, 0.619608],
[0.368627, 0.14902, 0.631373],
[0.356863, 0.133333, 0.643137],
[0.345098, 0.14902, 0.654902],
[0.333333, 0.203922, 0.666667],
[0.321569, 0.282353, 0.678431],
[0.309804, 0.376471, 0.690196],
[0.298039, 0.47451, 0.701961],
[0.286275, 0.552941, 0.713725],
[0.27451, 0.607843, 0.72549],
[0.266667, 0.627451, 0.733333],
[0.254902, 0.607843, 0.745098],
[0.243137, 0.552941, 0.756863],
[0.235294, 0.47451, 0.764706],
[0.223529, 0.380392, 0.776471],
[0.211765, 0.282353, 0.788235],
[0.203922, 0.203922, 0.796078],
[0.192157, 0.14902, 0.807843],
[0.184314, 0.133333, 0.815686],
[0.176471, 0.14902, 0.823529],
[0.164706, 0.203922, 0.835294],
[0.156863, 0.282353, 0.843137],
[0.14902, 0.376471, 0.85098],
[0.141176, 0.47451, 0.858824],
[0.129412, 0.552941, 0.870588],
[0.121569, 0.607843, 0.878431],
[0.113725, 0.627451, 0.886275],
[0.105882, 0.607843, 0.894118],
[0.0980392, 0.552941, 0.901961],
[0.0941176, 0.47451, 0.905882],
[0.0862745, 0.380392, 0.913725],
[0.0784314, 0.282353, 0.921569],
[0.0745098, 0.203922, 0.92549],
[0.0666667, 0.14902, 0.933333],
[0.0588235, 0.133333, 0.941176],
[0.054902, 0.14902, 0.945098],
[0.0509804, 0.203922, 0.94902],
[0.0431373, 0.282353, 0.956863],
[0.0509804, 0.376471, 0.960784],
[0.0352941, 0.47451, 0.964706],
[0.0313725, 0.552941, 0.968627],
[0.027451, 0.607843, 0.972549],
[0.0235294, 0.627451, 0.976471],
[0.0196078, 0.607843, 0.980392],
[0.0156863, 0.552941, 0.984314],
[0.0156863, 0.47451, 0.984314],
[0.0117647, 0.380392, 0.988235],
[0.00784314, 0.282353, 0.992157],
[0.00784314, 0.203922, 0.992157],
[0.00392157, 0.14902, 0.996078],
[0.00392157, 0.133333, 0.996078],
[0.00392157, 0.14902, 0.996078],
[0.00392157, 0.203922, 0.996078],
[0.00392157, 0.282353, 0.996078],
[0.00392157, 0.376471, 1.],
[0.00392157, 0.47451, 0.996078],
[0.00392157, 0.552941, 0.996078],
[0.00392157, 0.607843, 0.996078],
[0.00392157, 0.627451, 0.996078],
[0.00392157, 0.607843, 0.996078],
[0.00784314, 0.552941, 0.992157],
[0.00784314, 0.47451, 0.992157],
[0.0117647, 0.380392, 0.988235],
[0.0156863, 0.282353, 0.984314],
[0.0156863, 0.203922, 0.984314],
[0.0196078, 0.14902, 0.980392],
[0.0235294, 0.133333, 0.976471],
[0.027451, 0.14902, 0.972549],
[0.0313725, 0.203922, 0.968627],
[0.0352941, 0.282353, 0.964706],
[0.0509804, 0.376471, 0.960784],
[0.0431373, 0.47451, 0.956863],
[0.0509804, 0.552941, 0.94902],
[0.054902, 0.607843, 0.945098],
[0.0588235, 0.627451, 0.941176],
[0.0666667, 0.607843, 0.933333],
[0.0745098, 0.552941, 0.92549],
[0.0784314, 0.47451, 0.921569],
[0.0862745, 0.380392, 0.913725],
[0.0941176, 0.282353, 0.905882],
[0.0980392, 0.203922, 0.901961],
[0.105882, 0.14902, 0.894118],
[0.113725, 0.133333, 0.886275],
[0.121569, 0.14902, 0.878431],
[0.129412, 0.203922, 0.870588],
[0.141176, 0.282353, 0.858824],
[0.14902, 0.376471, 0.85098],
[0.156863, 0.47451, 0.843137],
[0.164706, 0.552941, 0.835294],
[0.176471, 0.607843, 0.823529],
[0.184314, 0.627451, 0.815686],
[0.192157, 0.607843, 0.807843],
[0.203922, 0.552941, 0.796078],
[0.211765, 0.47451, 0.788235],
[0.223529, 0.380392, 0.776471],
[0.235294, 0.282353, 0.764706],
[0.243137, 0.203922, 0.756863],
[0.254902, 0.14902, 0.745098],
[0.266667, 0.133333, 0.733333],
[0.27451, 0.14902, 0.72549],
[0.286275, 0.203922, 0.713725],
[0.298039, 0.282353, 0.701961],
[0.309804, 0.376471, 0.690196],
[0.321569, 0.47451, 0.678431],
[0.333333, 0.552941, 0.666667],
[0.345098, 0.607843, 0.654902],
[0.356863, 0.627451, 0.643137],
[0.368627, 0.607843, 0.631373],
[0.380392, 0.552941, 0.619608],
[0.392157, 0.47451, 0.607843],
[0.403922, 0.376471, 0.596078],
[0.415686, 0.282353, 0.584314],
[0.427451, 0.203922, 0.572549],
[0.439216, 0.14902, 0.560784],
[0.45098, 0.133333, 0.54902],
[0.462745, 0.14902, 0.537255],
[0.47451, 0.203922, 0.52549],
[0.486275, 0.282353, 0.513725],
[0.501961, 0.380392, 0.498039],
[0.513725, 0.47451, 0.486275],
[0.52549, 0.552941, 0.47451],
[0.537255, 0.607843, 0.462745],
[0.54902, 0.627451, 0.45098],
[0.560784, 0.607843, 0.439216],
[0.572549, 0.552941, 0.427451],
[0.584314, 0.47451, 0.415686],
[0.596078, 0.376471, 0.403922],
[0.607843, 0.282353, 0.392157],
[0.619608, 0.203922, 0.380392],
[0.631373, 0.14902, 0.368627],
[0.643137, 0.133333, 0.356863],
[0.654902, 0.14902, 0.345098],
[0.666667, 0.203922, 0.333333],
[0.678431, 0.282353, 0.321569],
[0.690196, 0.380392, 0.309804],
[0.701961, 0.47451, 0.298039],
[0.713725, 0.552941, 0.286275],
[0.72549, 0.607843, 0.27451],
[0.733333, 0.627451, 0.266667],
[0.745098, 0.607843, 0.254902],
[0.756863, 0.552941, 0.243137],
[0.764706, 0.47451, 0.235294],
[0.776471, 0.376471, 0.223529],
[0.788235, 0.282353, 0.211765],
[0.796078, 0.203922, 0.203922],
[0.807843, 0.14902, 0.192157],
[0.815686, 0.133333, 0.184314],
[0.823529, 0.14902, 0.176471],
[0.835294, 0.203922, 0.164706],
[0.843137, 0.282353, 0.156863],
[0.85098, 0.380392, 0.14902],
[0.858824, 0.47451, 0.141176],
[0.870588, 0.552941, 0.129412],
[0.878431, 0.607843, 0.121569],
[0.886275, 0.627451, 0.113725],
[0.894118, 0.607843, 0.105882],
[0.901961, 0.552941, 0.0980392],
[0.905882, 0.47451, 0.0941176],
[0.913725, 0.376471, 0.0862745],
[0.921569, 0.282353, 0.0784314],
[0.92549, 0.203922, 0.0745098],
[0.933333, 0.14902, 0.0666667],
[0.941176, 0.133333, 0.0588235],
[0.945098, 0.14902, 0.054902],
[0.94902, 0.203922, 0.0509804],
[0.956863, 0.282353, 0.0431373],
[0.960784, 0.380392, 0.0509804],
[0.964706, 0.47451, 0.0352941],
[0.968627, 0.552941, 0.0313725],
[0.972549, 0.607843, 0.027451],
[0.976471, 0.627451, 0.0235294],
[0.980392, 0.607843, 0.0196078],
[0.984314, 0.552941, 0.0156863],
[0.984314, 0.47451, 0.0156863],
[0.988235, 0.376471, 0.0117647],
[0.992157, 0.282353, 0.00784314],
[0.992157, 0.203922, 0.00784314],
[0.996078, 0.14902, 0.00392157],
[0.996078, 0.133333, 0.00392157],
[0.996078, 0.14902, 0.00392157],
[0.996078, 0.203922, 0.00392157],
[0.996078, 0.282353, 0.00392157],
[1., 0.380392, 0.00392157],
[0.996078, 0.47451, 0.00392157],
[0.996078, 0.552941, 0.00392157],
[0.996078, 0.607843, 0.00392157],
[0.996078, 0.627451, 0.00392157],
[0.996078, 0.607843, 0.00392157],
[0.992157, 0.552941, 0.00784314],
[0.992157, 0.47451, 0.00784314],
[0.988235, 0.376471, 0.0117647],
[0.984314, 0.282353, 0.0156863],
[0.984314, 0.203922, 0.0156863],
[0.980392, 0.14902, 0.0196078],
[0.976471, 0.133333, 0.0235294],
[0.972549, 0.14902, 0.027451],
[0.968627, 0.203922, 0.0313725],
[0.964706, 0.282353, 0.0352941],
[0.960784, 0.380392, 0.0509804],
[0.956863, 0.47451, 0.0431373],
[0.94902, 0.552941, 0.0509804],
[0.945098, 0.607843, 0.054902],
[0.941176, 0.627451, 0.0588235],
[0.933333, 0.607843, 0.0666667],
[0.92549, 0.552941, 0.0745098],
[0.921569, 0.47451, 0.0784314],
[0.913725, 0.376471, 0.0862745],
[0.905882, 0.282353, 0.0941176],
[0.901961, 0.203922, 0.0980392],
[0.894118, 0.14902, 0.105882],
[0.886275, 0.133333, 0.113725],
[0.878431, 0.14902, 0.121569],
[0.870588, 0.203922, 0.129412],
[0.858824, 0.282353, 0.141176],
[0.85098, 0.380392, 0.14902],
[0.843137, 0.47451, 0.156863],
[0.835294, 0.552941, 0.164706],
[0.823529, 0.607843, 0.176471],
[0.815686, 0.627451, 0.184314],
[0.807843, 0.607843, 0.192157],
[0.796078, 0.552941, 0.203922],
[0.788235, 0.47451, 0.211765],
[0.776471, 0.376471, 0.223529],
[0.764706, 0.282353, 0.235294],
[0.756863, 0.203922, 0.243137],
[0.745098, 0.14902, 0.254902],
[0.733333, 0.133333, 0.266667],
[0.72549, 0.14902, 0.27451],
[0.713725, 0.203922, 0.286275],
[0.701961, 0.282353, 0.298039],
[0.690196, 0.380392, 0.309804],
[0.678431, 0.47451, 0.321569],
[0.666667, 0.552941, 0.333333],
[0.654902, 0.607843, 0.345098],
[0.643137, 0.627451, 0.356863],
[0.631373, 0.607843, 0.368627],
[0.619608, 0.552941, 0.380392],
[0.607843, 0.47451, 0.392157],
[0.596078, 0.376471, 0.403922],
[0.584314, 0.282353, 0.415686],
[0.572549, 0.203922, 0.427451],
[0.560784, 0.14902, 0.439216],
[0.54902, 0.133333, 0.45098],
[0.537255, 0.14902, 0.462745],
[0.52549, 0.203922, 0.47451],
[0.52549, 0.203922, 0.47451]]

test_cm = LinearSegmentedColormap.from_list(__file__, cm_data)


if __name__ == "__main__":
    import matplotlib.pyplot as plt
    import numpy as np

    try:
        from pycam02ucs.cm.viscm import viscm
        viscm(test_cm)
    except ImportError:
        print("pycam02ucs not found, falling back on simple display")
        plt.imshow(np.linspace(0, 100, 256)[None, :], aspect='auto',
                   cmap=test_cm)
    plt.show()
