from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0., 0., 0.],
[0., 0., 0.0196078],
[0., 0., 0.0392157],
[0., 0., 0.0588235],
[0., 0., 0.0784314],
[0., 0., 0.101961],
[0., 0., 0.121569],
[0., 0., 0.141176],
[0., 0., 0.160784],
[0., 0., 0.180392],
[0., 0., 0.203922],
[0., 0., 0.223529],
[0., 0., 0.243137],
[0., 0., 0.262745],
[0., 0., 0.282353],
[0., 0., 0.305882],
[0., 0., 0.32549],
[0., 0., 0.345098],
[0., 0., 0.364706],
[0., 0., 0.384314],
[0., 0., 0.407843],
[0., 0., 0.427451],
[0., 0., 0.447059],
[0., 0., 0.466667],
[0., 0., 0.486275],
[0., 0., 0.509804],
[0., 0., 0.529412],
[0., 0., 0.54902],
[0., 0., 0.568627],
[0., 0., 0.588235],
[0., 0., 0.611765],
[0., 0., 0.631373],
[0., 0., 0.65098],
[0., 0., 0.670588],
[0., 0., 0.690196],
[0., 0., 0.713725],
[0., 0., 0.733333],
[0., 0., 0.752941],
[0., 0., 0.772549],
[0., 0., 0.792157],
[0., 0., 0.815686],
[0., 0., 0.835294],
[0., 0., 0.854902],
[0., 0., 0.87451],
[0., 0., 0.894118],
[0., 0., 0.917647],
[0., 0., 0.937255],
[0., 0., 0.956863],
[0.0156863, 0., 0.976471],
[0.0352941, 0., 1.],
[0.054902, 0., 0.980392],
[0.0745098, 0., 0.960784],
[0.0901961, 0., 0.937255],
[0.109804, 0., 0.917647],
[0.129412, 0., 0.894118],
[0.14902, 0., 0.87451],
[0.164706, 0., 0.854902],
[0.184314, 0., 0.831373],
[0.203922, 0., 0.811765],
[0.223529, 0., 0.788235],
[0.239216, 0., 0.768627],
[0.258824, 0., 0.745098],
[0.278431, 0., 0.72549],
[0.298039, 0., 0.705882],
[0.317647, 0., 0.682353],
[0.317647, 0., 0.662745],
[0.317647, 0., 0.639216],
[0.317647, 0., 0.619608],
[0.317647, 0., 0.596078],
[0.317647, 0., 0.576471],
[0.317647, 0., 0.556863],
[0.317647, 0., 0.533333],
[0.313725, 0., 0.513725],
[0.313725, 0., 0.490196],
[0.313725, 0., 0.470588],
[0.313725, 0., 0.447059],
[0.313725, 0., 0.427451],
[0.313725, 0., 0.407843],
[0.313725, 0., 0.384314],
[0.309804, 0., 0.364706],
[0.329412, 0., 0.341176],
[0.34902, 0., 0.321569],
[0.368627, 0., 0.298039],
[0.388235, 0., 0.278431],
[0.407843, 0., 0.258824],
[0.427451, 0., 0.235294],
[0.447059, 0., 0.215686],
[0.466667, 0., 0.192157],
[0.486275, 0., 0.172549],
[0.505882, 0., 0.14902],
[0.52549, 0., 0.129412],
[0.545098, 0., 0.109804],
[0.564706, 0., 0.0862745],
[0.584314, 0., 0.0666667],
[0.603922, 0., 0.0431373],
[0.623529, 0., 0.0235294],
[0.643137, 0., 0.],
[0.662745, 0., 0.],
[0.682353, 0., 0.],
[0.705882, 0., 0.],
[0.72549, 0., 0.],
[0.745098, 0., 0.],
[0.768627, 0., 0.],
[0.788235, 0., 0.],
[0.807843, 0., 0.],
[0.831373, 0., 0.],
[0.85098, 0., 0.],
[0.870588, 0., 0.],
[0.894118, 0., 0.],
[0.913725, 0., 0.],
[1., 0., 0.],
[1., 0., 0.],
[1., 0., 0.],
[1., 0., 0.],
[1., 0.0196078, 0.],
[1., 0.0392157, 0.],
[1., 0.0627451, 0.],
[1., 0.0823529, 0.],
[1., 0.105882, 0.],
[1., 0.12549, 0.],
[1., 0.145098, 0.],
[1., 0.168627, 0.],
[1., 0.188235, 0.],
[1., 0.211765, 0.],
[1., 0.231373, 0.],
[1., 0.25098, 0.],
[1., 0.27451, 0.],
[1., 0.294118, 0.],
[1., 0.317647, 0.],
[1., 0.333333, 0.0156863],
[1., 0.352941, 0.0352941],
[1., 0.372549, 0.054902],
[1., 0.392157, 0.0745098],
[1., 0.411765, 0.0941176],
[1., 0.427451, 0.109804],
[1., 0.447059, 0.129412],
[1., 0.466667, 0.14902],
[1., 0.486275, 0.168627],
[1., 0.505882, 0.188235],
[1., 0.52549, 0.207843],
[1., 0.541176, 0.223529],
[1., 0.560784, 0.243137],
[1., 0.580392, 0.262745],
[1., 0.6, 0.282353],
[1., 0.619608, 0.301961],
[1., 0.639216, 0.321569],
[1., 0.639216, 0.301961],
[1., 0.639216, 0.278431],
[1., 0.639216, 0.254902],
[1., 0.639216, 0.231373],
[1., 0.639216, 0.207843],
[1., 0.639216, 0.184314],
[1., 0.639216, 0.160784],
[1., 0.639216, 0.141176],
[1., 0.639216, 0.117647],
[1., 0.639216, 0.0941176],
[1., 0.639216, 0.0705882],
[1., 0.639216, 0.0470588],
[1., 0.639216, 0.0235294],
[1., 0.639216, 0.],
[1., 0.639216, 0.],
[1., 0.639216, 0.],
[1., 0.639216, 0.],
[0.972549, 0.639216, 0.],
[0.941176, 0.639216, 0.],
[0.909804, 0.639216, 0.],
[0.882353, 0.639216, 0.],
[0.85098, 0.639216, 0.],
[0.819608, 0.639216, 0.],
[0.792157, 0.639216, 0.],
[0.760784, 0.639216, 0.],
[0.729412, 0.639216, 0.],
[0.701961, 0.639216, 0.],
[0.670588, 0.639216, 0.],
[0.639216, 0.639216, 0.],
[0.658824, 0.639216, 0.],
[0.678431, 0.639216, 0.],
[0.698039, 0.662745, 0.0117647],
[0.717647, 0.686275, 0.0235294],
[0.737255, 0.709804, 0.0352941],
[0.756863, 0.733333, 0.0470588],
[0.776471, 0.756863, 0.0627451],
[0.796078, 0.780392, 0.0745098],
[0.819608, 0.803922, 0.0862745],
[0.839216, 0.831373, 0.0980392],
[0.858824, 0.854902, 0.113725],
[0.878431, 0.878431, 0.12549],
[0.898039, 0.901961, 0.137255],
[0.917647, 0.92549, 0.14902],
[0.937255, 0.94902, 0.160784],
[0.956863, 0.972549, 0.176471],
[0.976471, 1., 0.188235],
[1., 1., 0.2],
[1., 1., 0.211765],
[1., 1., 0.227451],
[1., 1., 0.239216],
[1., 1., 0.25098],
[1., 1., 0.262745],
[1., 1., 0.278431],
[1., 1., 0.290196],
[1., 1., 0.301961],
[1., 1., 0.313725],
[1., 1., 0.32549],
[1., 1., 0.341176],
[1., 1., 0.352941],
[1., 1., 0.364706],
[1., 1., 0.376471],
[1., 1., 0.392157],
[1., 1., 0.403922],
[1., 1., 0.415686],
[1., 1., 0.427451],
[1., 1., 0.439216],
[1., 1., 0.454902],
[1., 1., 0.466667],
[1., 1., 0.478431],
[1., 1., 0.490196],
[1., 1., 0.505882],
[1., 1., 0.517647],
[1., 1., 0.529412],
[1., 1., 0.541176],
[1., 1., 0.556863],
[1., 1., 0.568627],
[1., 1., 0.580392],
[1., 1., 0.592157],
[1., 1., 0.603922],
[1., 1., 0.619608],
[1., 1., 0.631373],
[1., 1., 0.643137],
[1., 1., 0.654902],
[1., 1., 0.670588],
[1., 1., 0.682353],
[1., 1., 0.694118],
[1., 1., 0.705882],
[1., 1., 0.717647],
[1., 1., 0.733333],
[1., 1., 0.745098],
[1., 1., 0.756863],
[1., 1., 0.768627],
[1., 1., 0.784314],
[1., 1., 0.796078],
[1., 1., 0.807843],
[1., 1., 0.819608],
[1., 1., 0.835294],
[1., 1., 0.847059],
[1., 1., 0.858824],
[1., 1., 0.870588],
[1., 1., 0.882353],
[1., 1., 0.898039],
[1., 1., 0.909804],
[1., 1., 0.921569],
[1., 1., 0.933333],
[1., 1., 0.94902],
[1., 1., 0.960784],
[1., 1., 0.972549],
[1., 1., 0.984314],
[1., 1., 1.]]

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()
