from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0., 0., 0.],
[0., 0.00392157, 0.00392157],
[0., 0.00784314, 0.00784314],
[0., 0.0117647, 0.0117647],
[0., 0.0156863, 0.0156863],
[0., 0.0313725, 0.0313725],
[0., 0.0470588, 0.0470588],
[0., 0.0627451, 0.0627451],
[0., 0.0823529, 0.0823529],
[0., 0.0980392, 0.0980392],
[0., 0.113725, 0.113725],
[0., 0.129412, 0.129412],
[0., 0.14902, 0.14902],
[0., 0.164706, 0.164706],
[0., 0.180392, 0.180392],
[0., 0.196078, 0.196078],
[0., 0.215686, 0.215686],
[0., 0.231373, 0.231373],
[0., 0.247059, 0.247059],
[0., 0.262745, 0.262745],
[0., 0.282353, 0.282353],
[0., 0.298039, 0.298039],
[0., 0.313725, 0.313725],
[0., 0.329412, 0.329412],
[0., 0.34902, 0.34902],
[0., 0.364706, 0.364706],
[0., 0.380392, 0.380392],
[0., 0.396078, 0.396078],
[0., 0.415686, 0.415686],
[0., 0.431373, 0.431373],
[0., 0.447059, 0.447059],
[0., 0.462745, 0.462745],
[0., 0.482353, 0.482353],
[0., 0.498039, 0.498039],
[0., 0.513725, 0.513725],
[0., 0.529412, 0.529412],
[0., 0.54902, 0.54902],
[0., 0.564706, 0.564706],
[0., 0.580392, 0.580392],
[0., 0.596078, 0.596078],
[0., 0.615686, 0.615686],
[0., 0.631373, 0.631373],
[0., 0.647059, 0.647059],
[0., 0.662745, 0.662745],
[0., 0.682353, 0.682353],
[0., 0.698039, 0.698039],
[0., 0.713725, 0.713725],
[0., 0.729412, 0.729412],
[0., 0.74902, 0.74902],
[0., 0.764706, 0.764706],
[0., 0.780392, 0.780392],
[0., 0.796078, 0.796078],
[0., 0.815686, 0.815686],
[0., 0.831373, 0.831373],
[0., 0.847059, 0.847059],
[0., 0.862745, 0.862745],
[0., 0.882353, 0.882353],
[0., 0.898039, 0.898039],
[0., 0.913725, 0.913725],
[0., 0.929412, 0.929412],
[0., 0.94902, 0.94902],
[0., 0.964706, 0.964706],
[0., 0.980392, 0.980392],
[0., 1., 1.],
[0., 1., 1.],
[0., 0.984314, 1.],
[0., 0.968627, 1.],
[0., 0.952941, 1.],
[0., 0.937255, 1.],
[0., 0.921569, 1.],
[0., 0.905882, 1.],
[0., 0.890196, 1.],
[0., 0.87451, 1.],
[0., 0.858824, 1.],
[0., 0.843137, 1.],
[0., 0.827451, 1.],
[0., 0.811765, 1.],
[0., 0.796078, 1.],
[0., 0.780392, 1.],
[0., 0.764706, 1.],
[0., 0.74902, 1.],
[0., 0.733333, 1.],
[0., 0.717647, 1.],
[0., 0.701961, 1.],
[0., 0.686275, 1.],
[0., 0.666667, 1.],
[0., 0.65098, 1.],
[0., 0.635294, 1.],
[0., 0.619608, 1.],
[0., 0.603922, 1.],
[0., 0.588235, 1.],
[0., 0.572549, 1.],
[0., 0.556863, 1.],
[0., 0.541176, 1.],
[0., 0.52549, 1.],
[0., 0.509804, 1.],
[0., 0.494118, 1.],
[0., 0.478431, 1.],
[0., 0.462745, 1.],
[0., 0.447059, 1.],
[0., 0.431373, 1.],
[0., 0.415686, 1.],
[0., 0.4, 1.],
[0., 0.384314, 1.],
[0., 0.368627, 1.],
[0., 0.352941, 1.],
[0., 0.333333, 1.],
[0., 0.317647, 1.],
[0., 0.301961, 1.],
[0., 0.286275, 1.],
[0., 0.270588, 1.],
[0., 0.254902, 1.],
[0., 0.239216, 1.],
[0., 0.223529, 1.],
[0., 0.207843, 1.],
[0., 0.192157, 1.],
[0., 0.176471, 1.],
[0., 0.160784, 1.],
[0., 0.145098, 1.],
[0., 0.129412, 1.],
[0., 0.113725, 1.],
[0., 0.0980392, 1.],
[0., 0.0823529, 1.],
[0., 0.0666667, 1.],
[0., 0.0509804, 1.],
[0., 0.0352941, 1.],
[0., 0.0196078, 1.],
[0., 0., 1.],
[0., 0., 1.],
[0.0156863, 0., 1.],
[0.0313725, 0., 1.],
[0.0470588, 0., 1.],
[0.0627451, 0., 1.],
[0.0784314, 0., 1.],
[0.0941176, 0., 1.],
[0.109804, 0., 1.],
[0.12549, 0., 1.],
[0.141176, 0., 1.],
[0.156863, 0., 1.],
[0.172549, 0., 1.],
[0.188235, 0., 1.],
[0.203922, 0., 1.],
[0.219608, 0., 1.],
[0.235294, 0., 1.],
[0.25098, 0., 1.],
[0.266667, 0., 1.],
[0.282353, 0., 1.],
[0.298039, 0., 1.],
[0.313725, 0., 1.],
[0.333333, 0., 1.],
[0.34902, 0., 1.],
[0.364706, 0., 1.],
[0.380392, 0., 1.],
[0.396078, 0., 1.],
[0.411765, 0., 1.],
[0.427451, 0., 1.],
[0.443137, 0., 1.],
[0.458824, 0., 1.],
[0.47451, 0., 1.],
[0.490196, 0., 1.],
[0.505882, 0., 1.],
[0.521569, 0., 1.],
[0.537255, 0., 1.],
[0.552941, 0., 1.],
[0.568627, 0., 1.],
[0.584314, 0., 1.],
[0.6, 0., 1.],
[0.615686, 0., 1.],
[0.631373, 0., 1.],
[0.647059, 0., 1.],
[0.666667, 0., 1.],
[0.682353, 0., 1.],
[0.698039, 0., 1.],
[0.713725, 0., 1.],
[0.729412, 0., 1.],
[0.745098, 0., 1.],
[0.760784, 0., 1.],
[0.776471, 0., 1.],
[0.792157, 0., 1.],
[0.807843, 0., 1.],
[0.823529, 0., 1.],
[0.839216, 0., 1.],
[0.854902, 0., 1.],
[0.870588, 0., 1.],
[0.886275, 0., 1.],
[0.901961, 0., 1.],
[0.917647, 0., 1.],
[0.933333, 0., 1.],
[0.94902, 0., 1.],
[0.964706, 0., 1.],
[0.980392, 0., 1.],
[1., 0., 1.],
[1., 0., 1.],
[1., 0., 0.984314],
[1., 0., 0.968627],
[1., 0., 0.952941],
[1., 0., 0.937255],
[1., 0., 0.921569],
[1., 0., 0.905882],
[1., 0., 0.890196],
[1., 0., 0.87451],
[1., 0., 0.854902],
[1., 0., 0.839216],
[1., 0., 0.823529],
[1., 0., 0.807843],
[1., 0., 0.792157],
[1., 0., 0.776471],
[1., 0., 0.760784],
[1., 0., 0.745098],
[1., 0., 0.729412],
[1., 0., 0.709804],
[1., 0., 0.694118],
[1., 0., 0.678431],
[1., 0., 0.662745],
[1., 0., 0.647059],
[1., 0., 0.631373],
[1., 0., 0.615686],
[1., 0., 0.6],
[1., 0., 0.584314],
[1., 0., 0.564706],
[1., 0., 0.54902],
[1., 0., 0.533333],
[1., 0., 0.517647],
[1., 0., 0.501961],
[1., 0., 0.486275],
[1., 0., 0.470588],
[1., 0., 0.454902],
[1., 0., 0.439216],
[1., 0., 0.419608],
[1., 0., 0.403922],
[1., 0., 0.388235],
[1., 0., 0.372549],
[1., 0., 0.356863],
[1., 0., 0.341176],
[1., 0., 0.32549],
[1., 0., 0.309804],
[1., 0., 0.294118],
[1., 0., 0.27451],
[1., 0., 0.258824],
[1., 0., 0.243137],
[1., 0., 0.227451],
[1., 0., 0.211765],
[1., 0., 0.196078],
[1., 0., 0.180392],
[1., 0., 0.164706],
[1., 0., 0.14902],
[1., 0., 0.129412],
[1., 0., 0.113725],
[1., 0., 0.0980392],
[1., 0., 0.0823529],
[1., 0., 0.0666667],
[1., 0., 0.0509804],
[1., 0., 0.0352941],
[1., 0., 0.0196078],
[1., 0., 0.],
[1., 0., 0.]]

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