Skip to content

Instantly share code, notes, and snippets.

@theodoregoetz
Created September 5, 2015 20:09
Show Gist options
  • Save theodoregoetz/ba2008900dc403af9d79 to your computer and use it in GitHub Desktop.
Save theodoregoetz/ba2008900dc403af9d79 to your computer and use it in GitHub Desktop.
viridis-like colormap going all the way to white instead of yellow
from matplotlib.colors import LinearSegmentedColormap
from numpy import nan, inf
# Used to reconstruct the colormap in pycam02ucs.cm.viscm
parameters = {'xp': [22.674387857633945, -10.903679653679603, -27.867965367965326, -46.32034632034626, 9.9296536796537396, -1.2562144886363136],
'yp': [-20.102530541012214, -39.58333333333333, -51.19047619047619, 60.714285714285694, 66.369047619047592, -0.46657986111111427],
'min_Jp': 18.8671875,
'max_Jp': 99.79166666666667}
cm_data = [[ 0.26700126, 0.00495011, 0.32938542],
[ 0.2675047 , 0.01376658, 0.3343288 ],
[ 0.2679605 , 0.02286997, 0.33927239],
[ 0.26836956, 0.03225882, 0.34421742],
[ 0.26873256, 0.04189182, 0.34916517],
[ 0.2690482 , 0.05088905, 0.35411805],
[ 0.26931426, 0.05914864, 0.3590789 ],
[ 0.2695349 , 0.06684456, 0.36404617],
[ 0.26970998, 0.07409699, 0.3690209 ],
[ 0.26983912, 0.0809905 , 0.37400407],
[ 0.26992171, 0.08758726, 0.37899654],
[ 0.26995164, 0.0939392 , 0.38400248],
[ 0.2699325 , 0.10007857, 0.38901937],
[ 0.26986343, 0.10603461, 0.39404728],
[ 0.26974287, 0.11183159, 0.39908641],
[ 0.26956895, 0.11748972, 0.4041367 ],
[ 0.26933959, 0.12302608, 0.4091979 ],
[ 0.2690524 , 0.12845532, 0.41426944],
[ 0.26870027, 0.13379302, 0.41935335],
[ 0.26828484, 0.1390473 , 0.42444552],
[ 0.26780307, 0.14422811, 0.42954439],
[ 0.26725159, 0.1493444 , 0.43464803],
[ 0.26662673, 0.15440432, 0.43975414],
[ 0.26592462, 0.15941528, 0.44485997],
[ 0.2651411 , 0.16438411, 0.44996231],
[ 0.26427178, 0.16931714, 0.45505746],
[ 0.26331205, 0.17422025, 0.46014118],
[ 0.26225707, 0.17909897, 0.46520868],
[ 0.2611018 , 0.18395845, 0.47025457],
[ 0.25984104, 0.18880356, 0.47527285],
[ 0.25846941, 0.19363888, 0.48025683],
[ 0.25698144, 0.19846871, 0.48519917],
[ 0.25537155, 0.2032971 , 0.49009181],
[ 0.25363416, 0.20812783, 0.49492596],
[ 0.25176371, 0.21296439, 0.4996921 ],
[ 0.24975472, 0.21781003, 0.50437997],
[ 0.24760191, 0.22266767, 0.50897858],
[ 0.24530027, 0.22753991, 0.51347624],
[ 0.24284374, 0.23242953, 0.51786097],
[ 0.24022209, 0.23734052, 0.52212099],
[ 0.23743856, 0.24227187, 0.52624087],
[ 0.23449065, 0.24722452, 0.53020665],
[ 0.23137687, 0.2521989 , 0.53400409],
[ 0.22809698, 0.25719491, 0.53761892],
[ 0.22464056, 0.26221563, 0.54103748],
[ 0.22102136, 0.26725609, 0.54424467],
[ 0.21724526, 0.27231401, 0.54722731],
[ 0.21331753, 0.27738734, 0.54997311],
[ 0.20924009, 0.28247511, 0.55247017],
[ 0.20503611, 0.28756997, 0.55470963],
[ 0.20072073, 0.29266742, 0.55668417],
[ 0.19630451, 0.29776464, 0.55838707],
[ 0.19181779, 0.30285342, 0.55981699],
[ 0.18728483, 0.307928 , 0.56097392],
[ 0.18273029, 0.31298309, 0.56185975],
[ 0.17818816, 0.31801151, 0.56248099],
[ 0.17369001, 0.32300754, 0.56284549],
[ 0.16927267, 0.3279648 , 0.56296481],
[ 0.16496903, 0.33287876, 0.56285061],
[ 0.16081574, 0.33774455, 0.56251745],
[ 0.15685394, 0.34255681, 0.56198367],
[ 0.15311234, 0.34731386, 0.56126269],
[ 0.14962488, 0.35201301, 0.56037146],
[ 0.14643291, 0.35664987, 0.55933328],
[ 0.14355505, 0.36122576, 0.55815918],
[ 0.14101658, 0.36574007, 0.55686541],
[ 0.1388437 , 0.37019148, 0.5554716 ],
[ 0.13705362, 0.37458028, 0.55399387],
[ 0.13565242, 0.37890882, 0.5524419 ],
[ 0.13464687, 0.38317834, 0.55082879],
[ 0.13403854, 0.38739039, 0.54916668],
[ 0.13382949, 0.3915451 , 0.54747372],
[ 0.13400503, 0.39564621, 0.54575352],
[ 0.13455185, 0.3996961 , 0.54401439],
[ 0.13545357, 0.40369707, 0.54226438],
[ 0.13669076, 0.40765151, 0.54051065],
[ 0.13824169, 0.41156187, 0.5387595 ],
[ 0.14008301, 0.41543063, 0.53701638],
[ 0.14219109, 0.41925997, 0.53528783],
[ 0.14454103, 0.42305246, 0.53357753],
[ 0.14710775, 0.42681092, 0.53188664],
[ 0.14986765, 0.43053777, 0.53021784],
[ 0.15279807, 0.43423536, 0.52857323],
[ 0.1558775 , 0.43790601, 0.52695439],
[ 0.1590858 , 0.44155197, 0.52536241],
[ 0.16240422, 0.44517543, 0.52379792],
[ 0.16581552, 0.44877852, 0.52226112],
[ 0.16930389, 0.45236328, 0.52075182],
[ 0.17285498, 0.45593169, 0.51926948],
[ 0.17645581, 0.45948567, 0.51781319],
[ 0.18009472, 0.46302703, 0.51638174],
[ 0.18376132, 0.46655752, 0.51497361],
[ 0.18744638, 0.47007882, 0.51358698],
[ 0.19114177, 0.47359253, 0.5122198 ],
[ 0.1948404 , 0.47710014, 0.51086974],
[ 0.1985361 , 0.48060303, 0.50953474],
[ 0.20222358, 0.48410243, 0.50821324],
[ 0.20589852, 0.48759977, 0.50690054],
[ 0.20955735, 0.49109622, 0.50559341],
[ 0.2131972 , 0.49459285, 0.50428847],
[ 0.21681592, 0.49809065, 0.50298215],
[ 0.22041204, 0.50159052, 0.50167074],
[ 0.22398469, 0.50509327, 0.50035038],
[ 0.22753361, 0.50859958, 0.49901711],
[ 0.23105913, 0.51211007, 0.49766684],
[ 0.23456209, 0.51562526, 0.49629541],
[ 0.23804381, 0.5191454 , 0.49490005],
[ 0.24150619, 0.52267089, 0.4934757 ],
[ 0.2449516 , 0.52620203, 0.49201705],
[ 0.24838279, 0.52973892, 0.49051972],
[ 0.25180295, 0.53328158, 0.48897932],
[ 0.25521563, 0.53682992, 0.48739148],
[ 0.25862476, 0.54038379, 0.48575188],
[ 0.26203458, 0.54394289, 0.48405623],
[ 0.2654496 , 0.54750679, 0.48230139],
[ 0.26887464, 0.55107513, 0.48048219],
[ 0.27231474, 0.55464743, 0.47859409],
[ 0.27577514, 0.55822308, 0.47663314],
[ 0.2792612 , 0.56180141, 0.47459547],
[ 0.28277842, 0.56538168, 0.47247738],
[ 0.2863324 , 0.56896307, 0.47027525],
[ 0.28992874, 0.57254474, 0.46798571],
[ 0.29357314, 0.57612578, 0.46560498],
[ 0.29727123, 0.57970524, 0.46312972],
[ 0.30102859, 0.58328212, 0.46055687],
[ 0.30485071, 0.58685538, 0.45788354],
[ 0.30874298, 0.59042393, 0.45510697],
[ 0.31271062, 0.59398668, 0.45222452],
[ 0.31675882, 0.59754252, 0.44923288],
[ 0.3208926 , 0.60109035, 0.44612907],
[ 0.32511655, 0.60462894, 0.44291155],
[ 0.32943514, 0.60815712, 0.43957815],
[ 0.33385264, 0.6116737 , 0.43612679],
[ 0.33837303, 0.61517748, 0.43255545],
[ 0.34300009, 0.61866724, 0.42886221],
[ 0.34773731, 0.62214179, 0.42504517],
[ 0.35258883, 0.62559997, 0.42109902],
[ 0.35755719, 0.62904049, 0.41702419],
[ 0.36264506, 0.63246211, 0.4128194 ],
[ 0.36785501, 0.63586361, 0.40848282],
[ 0.37318936, 0.63924376, 0.40401262],
[ 0.37865024, 0.6426013 , 0.3994069 ],
[ 0.38423956, 0.64593501, 0.39466373],
[ 0.38995907, 0.64924362, 0.38978109],
[ 0.39581033, 0.65252587, 0.38475687],
[ 0.40179511, 0.65578047, 0.37958785],
[ 0.40791592, 0.65900605, 0.37426842],
[ 0.41417252, 0.66220134, 0.36880007],
[ 0.42056594, 0.66536502, 0.36318019],
[ 0.42709713, 0.66849571, 0.35740596],
[ 0.43376697, 0.67159205, 0.35147437],
[ 0.44057625, 0.6746526 , 0.34538214],
[ 0.44752577, 0.67767592, 0.33912576],
[ 0.45461625, 0.68066049, 0.33270142],
[ 0.46184844, 0.68360476, 0.32610499],
[ 0.46922307, 0.68650715, 0.31933201],
[ 0.47674087, 0.68936598, 0.31237766],
[ 0.48440259, 0.69217955, 0.30523674],
[ 0.492209 , 0.69494604, 0.29790361],
[ 0.50016088, 0.69766361, 0.29037223],
[ 0.50825902, 0.70033032, 0.2826361 ],
[ 0.51650423, 0.70294414, 0.27468826],
[ 0.52489728, 0.70550298, 0.2665213 ],
[ 0.53344307, 0.70800384, 0.25811856],
[ 0.54214444, 0.71044391, 0.24946733],
[ 0.55099806, 0.71282154, 0.24056732],
[ 0.56000459, 0.71513421, 0.23140918],
[ 0.56916444, 0.71737932, 0.22198355],
[ 0.57847768, 0.71955424, 0.21228141],
[ 0.5879633 , 0.72165164, 0.20225329],
[ 0.597609 , 0.72367125, 0.19191615],
[ 0.6074089 , 0.72561136, 0.18127444],
[ 0.61737726, 0.72746492, 0.17029147],
[ 0.62751572, 0.72922762, 0.15896148],
[ 0.63779965, 0.73090226, 0.14734441],
[ 0.64827001, 0.73247303, 0.13537013],
[ 0.65887057, 0.7339515 , 0.12320925],
[ 0.66964059, 0.73532122, 0.11086423],
[ 0.68052617, 0.73659345, 0.0986245 ],
[ 0.69151519, 0.7377671 , 0.08681632],
[ 0.70258606, 0.73884394, 0.0759976 ],
[ 0.71366977, 0.73984237, 0.06711982],
[ 0.72470027, 0.74078163, 0.06140542],
[ 0.7355908 , 0.74169054, 0.06012217],
[ 0.74623837, 0.74260716, 0.06399133],
[ 0.75653469, 0.74357568, 0.07274406],
[ 0.76638186, 0.74464074, 0.08533159],
[ 0.77570673, 0.74584106, 0.10050797],
[ 0.78446148, 0.74720819, 0.11720927],
[ 0.79264386, 0.74875567, 0.1347036 ],
[ 0.80027558, 0.75048634, 0.15252994],
[ 0.80738778, 0.75239813, 0.17039515],
[ 0.81401443, 0.75448707, 0.18809449],
[ 0.82021481, 0.75673371, 0.20561284],
[ 0.8260183 , 0.75913389, 0.22283072],
[ 0.83147326, 0.76167041, 0.23978165],
[ 0.83661719, 0.76433017, 0.25648821],
[ 0.84147614, 0.76710711, 0.27289893],
[ 0.84608123, 0.76998973, 0.28904386],
[ 0.85045908, 0.77296742, 0.30496401],
[ 0.85463093, 0.77603271, 0.32066881],
[ 0.8586158 , 0.77917871, 0.33616911],
[ 0.86243067, 0.78239916, 0.35147649],
[ 0.86609066, 0.78568837, 0.3666028 ],
[ 0.86960918, 0.78904122, 0.38155986],
[ 0.87299812, 0.79245306, 0.39635921],
[ 0.87626805, 0.79591974, 0.41101195],
[ 0.87942829, 0.79943754, 0.42552868],
[ 0.88248713, 0.8030031 , 0.43991939],
[ 0.88545193, 0.80661344, 0.45419342],
[ 0.8883347 , 0.81026666, 0.46830564],
[ 0.89113871, 0.81395949, 0.48230082],
[ 0.89386808, 0.81768956, 0.49619853],
[ 0.89652748, 0.82145492, 0.51000621],
[ 0.89912247, 0.82525389, 0.52372012],
[ 0.90166764, 0.82908506, 0.53727367],
[ 0.90415595, 0.83294647, 0.55075293],
[ 0.90659039, 0.83683685, 0.56416333],
[ 0.90898278, 0.84075497, 0.57745553],
[ 0.91133691, 0.84469954, 0.59063297],
[ 0.91364629, 0.84866972, 0.60375364],
[ 0.9159213 , 0.8526644 , 0.61677707],
[ 0.91817071, 0.85668239, 0.62967561],
[ 0.92038255, 0.8607235 , 0.64252706],
[ 0.92257243, 0.86478641, 0.65526659],
[ 0.92474124, 0.86887046, 0.66790509],
[ 0.92687833, 0.87297579, 0.68050381],
[ 0.92901171, 0.87710025, 0.6929466 ],
[ 0.93112033, 0.88124474, 0.70533964],
[ 0.93321534, 0.88540821, 0.71764329],
[ 0.93530509, 0.88958972, 0.72983269],
[ 0.93737255, 0.89379025, 0.74198689],
[ 0.93945254, 0.8980069 , 0.75397425],
[ 0.94151278, 0.90224191, 0.76593201],
[ 0.94358224, 0.90649278, 0.77775524],
[ 0.94564498, 0.91076057, 0.7895133 ],
[ 0.94771386, 0.91504404, 0.80116575],
[ 0.94978823, 0.91934303, 0.81272323],
[ 0.95186781, 0.92365734, 0.82419451],
[ 0.95396359, 0.92798583, 0.83554911],
[ 0.95606621, 0.93232903, 0.84682804],
[ 0.95819454, 0.93668501, 0.85797553],
[ 0.96033437, 0.94105463, 0.86904942],
[ 0.96250897, 0.94543541, 0.87998274],
[ 0.96470372, 0.94982801, 0.89083623],
[ 0.96694329, 0.95422944, 0.90154388],
[ 0.96921766, 0.9586394 , 0.9121567 ],
[ 0.9715515 , 0.96305407, 0.92261935],
[ 0.97394639, 0.96747065, 0.93296081],
[ 0.97643053, 0.9718826 , 0.94314137],
[ 0.97903257, 0.97628042, 0.95315054],
[ 0.98180795, 0.98064725, 0.96294742],
[ 0.98486061, 0.98495561, 0.97241012],
[ 0.98831033, 0.98918141, 0.98132686],
[ 0.99208484, 0.99339399, 0.98931597],
[ 0.99570395, 0.99775547, 0.996651 ]]
n = 5
for i in range(-n,0):
r = 1 - abs(i + 1)/n
for j in range(3):
cm_data[i][j] = r + (1-r) * cm_data[i][j]
print(i,cm_data[i])
cm_data = cm_data[::-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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment