from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
cm_data = [[0., 0., 0.],
[0.0156863, 0., 0.0117647],
[0.0352941, 0., 0.027451],
[0.0509804, 0., 0.0392157],
[0.0705882, 0., 0.054902],
[0.0862745, 0., 0.0745098],
[0.105882, 0., 0.0901961],
[0.121569, 0., 0.109804],
[0.141176, 0., 0.12549],
[0.156863, 0., 0.14902],
[0.176471, 0., 0.168627],
[0.196078, 0., 0.188235],
[0.211765, 0., 0.207843],
[0.227451, 0., 0.231373],
[0.239216, 0., 0.247059],
[0.25098, 0., 0.266667],
[0.266667, 0., 0.282353],
[0.270588, 0., 0.301961],
[0.282353, 0., 0.317647],
[0.290196, 0., 0.337255],
[0.301961, 0., 0.356863],
[0.309804, 0., 0.372549],
[0.313725, 0., 0.392157],
[0.321569, 0., 0.407843],
[0.32549, 0., 0.427451],
[0.333333, 0., 0.443137],
[0.329412, 0., 0.462745],
[0.337255, 0., 0.478431],
[0.341176, 0., 0.498039],
[0.345098, 0., 0.517647],
[0.337255, 0., 0.533333],
[0.341176, 0., 0.552941],
[0.341176, 0., 0.568627],
[0.341176, 0., 0.588235],
[0.333333, 0., 0.603922],
[0.329412, 0., 0.623529],
[0.329412, 0., 0.639216],
[0.329412, 0., 0.658824],
[0.32549, 0., 0.678431],
[0.309804, 0., 0.694118],
[0.305882, 0., 0.713725],
[0.301961, 0., 0.729412],
[0.298039, 0., 0.74902],
[0.278431, 0., 0.764706],
[0.27451, 0., 0.784314],
[0.266667, 0., 0.8],
[0.258824, 0., 0.819608],
[0.235294, 0., 0.839216],
[0.227451, 0., 0.854902],
[0.215686, 0., 0.87451],
[0.207843, 0., 0.890196],
[0.180392, 0., 0.909804],
[0.168627, 0., 0.92549],
[0.156863, 0., 0.945098],
[0.141176, 0., 0.960784],
[0.129412, 0., 0.980392],
[0.0980392, 0., 1.],
[0.0823529, 0., 1.],
[0.0627451, 0., 1.],
[0.0470588, 0., 1.],
[0.0156863, 0., 1.],
[0., 0., 1.],
[0., 0.0156863, 1.],
[0., 0.0313725, 1.],
[0., 0.0627451, 1.],
[0., 0.0823529, 1.],
[0., 0.0980392, 1.],
[0., 0.113725, 1.],
[0., 0.14902, 1.],
[0., 0.164706, 1.],
[0., 0.180392, 1.],
[0., 0.2, 1.],
[0., 0.215686, 1.],
[0., 0.247059, 1.],
[0., 0.262745, 1.],
[0., 0.282353, 1.],
[0., 0.298039, 1.],
[0., 0.329412, 1.],
[0., 0.34902, 1.],
[0., 0.364706, 1.],
[0., 0.380392, 1.],
[0., 0.415686, 1.],
[0., 0.431373, 1.],
[0., 0.447059, 1.],
[0., 0.466667, 1.],
[0., 0.498039, 1.],
[0., 0.513725, 1.],
[0., 0.529412, 1.],
[0., 0.54902, 1.],
[0., 0.564706, 1.],
[0., 0.596078, 1.],
[0., 0.615686, 1.],
[0., 0.631373, 1.],
[0., 0.647059, 1.],
[0., 0.682353, 1.],
[0., 0.698039, 1.],
[0., 0.713725, 1.],
[0., 0.733333, 1.],
[0., 0.764706, 1.],
[0., 0.780392, 1.],
[0., 0.796078, 1.],
[0., 0.815686, 1.],
[0., 0.847059, 1.],
[0., 0.862745, 1.],
[0., 0.882353, 1.],
[0., 0.898039, 1.],
[0., 0.913725, 1.],
[0., 0.94902, 1.],
[0., 0.964706, 1.],
[0., 0.980392, 1.],
[0., 1., 1.],
[0., 1., 0.964706],
[0., 1., 0.94902],
[0., 1., 0.933333],
[0., 1., 0.913725],
[0., 1., 0.882353],
[0., 1., 0.862745],
[0., 1., 0.847059],
[0., 1., 0.831373],
[0., 1., 0.796078],
[0., 1., 0.780392],
[0., 1., 0.764706],
[0., 1., 0.74902],
[0., 1., 0.733333],
[0., 1., 0.698039],
[0., 1., 0.682353],
[0., 1., 0.666667],
[0., 1., 0.647059],
[0., 1., 0.615686],
[0., 1., 0.596078],
[0., 1., 0.580392],
[0., 1., 0.564706],
[0., 1., 0.529412],
[0., 1., 0.513725],
[0., 1., 0.498039],
[0., 1., 0.482353],
[0., 1., 0.447059],
[0., 1., 0.431373],
[0., 1., 0.415686],
[0., 1., 0.4],
[0., 1., 0.380392],
[0., 1., 0.34902],
[0., 1., 0.329412],
[0., 1., 0.313725],
[0., 1., 0.298039],
[0., 1., 0.262745],
[0., 1., 0.247059],
[0., 1., 0.231373],
[0., 1., 0.215686],
[0., 1., 0.180392],
[0., 1., 0.164706],
[0., 1., 0.14902],
[0., 1., 0.133333],
[0., 1., 0.0980392],
[0., 1., 0.0823529],
[0., 1., 0.0627451],
[0., 1., 0.0470588],
[0., 1., 0.0313725],
[0., 1., 0.],
[0.0156863, 1., 0.],
[0.0313725, 1., 0.],
[0.0470588, 1., 0.],
[0.0823529, 1., 0.],
[0.0980392, 1., 0.],
[0.113725, 1., 0.],
[0.129412, 1., 0.],
[0.164706, 1., 0.],
[0.180392, 1., 0.],
[0.2, 1., 0.],
[0.215686, 1., 0.],
[0.247059, 1., 0.],
[0.262745, 1., 0.],
[0.282353, 1., 0.],
[0.298039, 1., 0.],
[0.313725, 1., 0.],
[0.34902, 1., 0.],
[0.364706, 1., 0.],
[0.380392, 1., 0.],
[0.396078, 1., 0.],
[0.431373, 1., 0.],
[0.447059, 1., 0.],
[0.466667, 1., 0.],
[0.482353, 1., 0.],
[0.513725, 1., 0.],
[0.529412, 1., 0.],
[0.54902, 1., 0.],
[0.564706, 1., 0.],
[0.6, 1., 0.],
[0.615686, 1., 0.],
[0.631373, 1., 0.],
[0.647059, 1., 0.],
[0.662745, 1., 0.],
[0.698039, 1., 0.],
[0.713725, 1., 0.],
[0.733333, 1., 0.],
[0.74902, 1., 0.],
[0.780392, 1., 0.],
[0.796078, 1., 0.],
[0.815686, 1., 0.],
[0.831373, 1., 0.],
[0.866667, 1., 0.],
[0.882353, 1., 0.],
[0.898039, 1., 0.],
[0.913725, 1., 0.],
[0.94902, 1., 0.],
[0.964706, 1., 0.],
[0.980392, 1., 0.],
[1., 1., 0.],
[1., 0.980392, 0.],
[1., 0.94902, 0.],
[1., 0.933333, 0.],
[1., 0.913725, 0.],
[1., 0.898039, 0.],
[1., 0.866667, 0.],
[1., 0.847059, 0.],
[1., 0.831373, 0.],
[1., 0.815686, 0.],
[1., 0.780392, 0.],
[1., 0.764706, 0.],
[1., 0.74902, 0.],
[1., 0.733333, 0.],
[1., 0.698039, 0.],
[1., 0.682353, 0.],
[1., 0.666667, 0.],
[1., 0.647059, 0.],
[1., 0.631373, 0.],
[1., 0.6, 0.],
[1., 0.580392, 0.],
[1., 0.564706, 0.],
[1., 0.54902, 0.],
[1., 0.513725, 0.],
[1., 0.498039, 0.],
[1., 0.482353, 0.],
[1., 0.466667, 0.],
[1., 0.431373, 0.],
[1., 0.415686, 0.],
[1., 0.4, 0.],
[1., 0.380392, 0.],
[1., 0.34902, 0.],
[1., 0.333333, 0.],
[1., 0.313725, 0.],
[1., 0.298039, 0.],
[1., 0.282353, 0.],
[1., 0.247059, 0.],
[1., 0.231373, 0.],
[1., 0.215686, 0.],
[1., 0.2, 0.],
[1., 0.164706, 0.],
[1., 0.14902, 0.],
[1., 0.133333, 0.],
[1., 0.113725, 0.],
[1., 0.0823529, 0.],
[1., 0.0666667, 0.],
[1., 0.0470588, 0.],
[1., 0.0313725, 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()
