Skip to content

Commit

Permalink
Add Mathematica colormaps
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed May 2, 2020
1 parent e88995d commit 1126d96
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 4 deletions.
63 changes: 61 additions & 2 deletions build/mathcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ document.getElementsByTagName( 'head' )[0].appendChild( mathcellStyle );

// data from lib/matplotlib/_cm.py with clipping to [0,1] as for CSS

var colormaps = {
var matplotlib = {

gray: { r: [ [ x => x, [0,1] ] ],
g: [ [ x => x, [0,1] ] ],
Expand Down Expand Up @@ -898,10 +898,69 @@ var colormaps = {
[ x => 1, [.375,.64] ], [ lerp( [.64,1], [.91,0] ), [.64,.91] ],
[ x => 0, [.91,1] ] ],
b: [ [ lerp( [0,.5], [.11,1] ), [0,.11] ], [ x => 1, [.11,.34] ],
[ lerp( [.34,1], [.65,0] ), [.34,.65] ], [ x => 0, [.65,1] ] ] }
[ lerp( [.34,1], [.65,0] ), [.34,.65] ], [ x => 0, [.65,1] ] ] },

}

// analyticphysics.com/Coding Methods/Reverse Engineering Mathematica Colormaps.htm

var mathematica = {

density: { r: [ [ x => .129 + 1.532*x, [0,.5] ], [ x => .775 + .25*x, [.5,.9] ],
[ x => 1, [.9,1] ] ],
g: [ [ x => .331 + .597*x, [0,1] ] ],
b: [ [ x => .54 + 1.18*x, [0,.1] ], [ x => .75 - .92*x, [.1,.5] ],
[ x => -.0975 + .775*x, [.5,.9] ], [ x => -.75 + 1.5*x, [.9,1] ] ] },

sunset: { r: [ [ x => 2.313*x, [0,.32] ], [ x => .391 + 1.181*x, [.32,.5] ],
[ x => .972 + .033*x, [.5,1] ] ],
g: [ [ x => .792*x, [0,.35] ], [ x => -.179 + 1.281*x, [.35,.82] ],
[ x => .281 + .719*x, [.82,1] ] ],
b: [ [ x => 3.025*x, [0,.17] ], [ x => .73 - 1.365*x, [.17,.5] ],
[ x => -.19 + .482*x, [.5,.67] ], [ x => -1.316 + 2.168*x, [.67,.82] ],
[ x => -2.032 + 3.031*x, [.82,1] ] ] },

watermelon: { r: [ [ x => .1 + 1.301*x, [0,.15] ], [ x => .137 + 1.029*x, [.15,.7] ],
[ x => .458 + .575*x, [.7,.85] ], [ x => 1.336 - .452*x, [.85,1] ] ],
g: [ [ x => .097 + 2.078*x - 1.327*x**2, [0,.55] ], [ x => .794 + .1*x, [.55,.72] ],
[ x => 1.56 - .973*x, [.72,.85] ], [ x => 2.897 - 2.536*x, [.85,1] ] ],
b: [ [ x => .0975 + .836*x, [0,.3] ], [ x => .012 + 1.13*x, [.3,.55] ],
[ x => .197 + .808*x, [.55,.72] ], [ x => 1.019 - .343*x, [.72,.85] ],
[ x => 2.886 - 2.525*x, [.85,1] ] ] },

cherry: { r: [ [ x => .216 + 2.437*x, [0,.14] ], [ x => .383 + 1.267*x, [.14,.3] ],
[ x => .57 + .621*x, [.3,.42] ], [ x => .721 + .272*x, [.42,1] ] ],
g: [ [ x => .215 - .409*x, [0,.15] ], [ x => .13 + .176*x, [.15,.3] ],
[ x => .089 + .0576*x + .86*x**2, [.3,1] ] ],
b: [ [ x => .215 - .405*x, [0,.15] ], [ x => .133 + .166*x, [.15,.28] ],
[ x => .075 + .12*x + .813*x**2, [.28,1] ] ] },

rust: { r: [ [ x => 1.556*x, [0,.5] ], [ x => .556 + .444*x, [.5,1] ] ],
g: [ [ x => .742*x, [0,.5] ], [ x => .265 + .208*x, [.5,1] ] ],
b: [ [ x => .191 - .242*x, [0,.5] ], [ x => .105 - .069*x, [.5,1] ] ] },

rainbow2: { r: [ [ x => .471 - 2.566*x, [0,.05] ],
[ x =>.423 - 2.045*x + 6.551*x**2 - 4.092*x**3 , [.05,1] ] ],
g: [ [ x => .107 + .24*x, [0,.07] ],
[ x => -.062 + 2.669*x - 2.012*x**2 - .476*x**4, [.07,1] ] ],
b: [ [ x => .523 + 2.692*x - 6.33*x**2, [0,.4] ],
[ x => 1.212 - 1.534*x, [.4,.55] ], [ x => .919 - .994*x, [.55,.62] ],
[ x => .556 - .421*x, [.62,1] ] ] },

temperature: { r: [ [ x => .176 + 1.633*x, [0,.15] ], [ x => .098 + 2.162*x, [.15,.35] ],
[ x => .092 + 3.098*x - 2.643*x**2, [.35,.67] ],
[ x => 1.362 - .547*x, [.67,1] ] ],
g: [ [ x => .305 + 1.627*x, [0,.4] ], [ x => .739 + .501*x, [.4,.5] ],
[ x => 1 - .018*x, [.5,.67] ], [ x => .185 + 3.688*x - 3.731*x**2, [.67,1] ] ],
b: [ [ x => .928 + .154*x, [0,.42] ], [ x => 1.404 - .985*x, [.42,.5] ],
[ x => 2.014 - 2.205*x, [.5,.58] ], [ x => 2.807 - 3.569*x, [.58,.67] ],
[ x => 1.561 - 1.703*x, [.67,.75] ], [ x => .637 - .473*x, [.75,1] ] ] },

}


var colormaps = Object.assign( {}, matplotlib, mathematica );


// return arrays of objects for all plots

Expand Down
63 changes: 61 additions & 2 deletions src/plot/colormaps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// data from lib/matplotlib/_cm.py with clipping to [0,1] as for CSS

var colormaps = {
var matplotlib = {

gray: { r: [ [ x => x, [0,1] ] ],
g: [ [ x => x, [0,1] ] ],
Expand Down Expand Up @@ -54,7 +54,66 @@ var colormaps = {
[ x => 1, [.375,.64] ], [ lerp( [.64,1], [.91,0] ), [.64,.91] ],
[ x => 0, [.91,1] ] ],
b: [ [ lerp( [0,.5], [.11,1] ), [0,.11] ], [ x => 1, [.11,.34] ],
[ lerp( [.34,1], [.65,0] ), [.34,.65] ], [ x => 0, [.65,1] ] ] }
[ lerp( [.34,1], [.65,0] ), [.34,.65] ], [ x => 0, [.65,1] ] ] },

}

// analyticphysics.com/Coding Methods/Reverse Engineering Mathematica Colormaps.htm

var mathematica = {

density: { r: [ [ x => .129 + 1.532*x, [0,.5] ], [ x => .775 + .25*x, [.5,.9] ],
[ x => 1, [.9,1] ] ],
g: [ [ x => .331 + .597*x, [0,1] ] ],
b: [ [ x => .54 + 1.18*x, [0,.1] ], [ x => .75 - .92*x, [.1,.5] ],
[ x => -.0975 + .775*x, [.5,.9] ], [ x => -.75 + 1.5*x, [.9,1] ] ] },

sunset: { r: [ [ x => 2.313*x, [0,.32] ], [ x => .391 + 1.181*x, [.32,.5] ],
[ x => .972 + .033*x, [.5,1] ] ],
g: [ [ x => .792*x, [0,.35] ], [ x => -.179 + 1.281*x, [.35,.82] ],
[ x => .281 + .719*x, [.82,1] ] ],
b: [ [ x => 3.025*x, [0,.17] ], [ x => .73 - 1.365*x, [.17,.5] ],
[ x => -.19 + .482*x, [.5,.67] ], [ x => -1.316 + 2.168*x, [.67,.82] ],
[ x => -2.032 + 3.031*x, [.82,1] ] ] },

watermelon: { r: [ [ x => .1 + 1.301*x, [0,.15] ], [ x => .137 + 1.029*x, [.15,.7] ],
[ x => .458 + .575*x, [.7,.85] ], [ x => 1.336 - .452*x, [.85,1] ] ],
g: [ [ x => .097 + 2.078*x - 1.327*x**2, [0,.55] ], [ x => .794 + .1*x, [.55,.72] ],
[ x => 1.56 - .973*x, [.72,.85] ], [ x => 2.897 - 2.536*x, [.85,1] ] ],
b: [ [ x => .0975 + .836*x, [0,.3] ], [ x => .012 + 1.13*x, [.3,.55] ],
[ x => .197 + .808*x, [.55,.72] ], [ x => 1.019 - .343*x, [.72,.85] ],
[ x => 2.886 - 2.525*x, [.85,1] ] ] },

cherry: { r: [ [ x => .216 + 2.437*x, [0,.14] ], [ x => .383 + 1.267*x, [.14,.3] ],
[ x => .57 + .621*x, [.3,.42] ], [ x => .721 + .272*x, [.42,1] ] ],
g: [ [ x => .215 - .409*x, [0,.15] ], [ x => .13 + .176*x, [.15,.3] ],
[ x => .089 + .0576*x + .86*x**2, [.3,1] ] ],
b: [ [ x => .215 - .405*x, [0,.15] ], [ x => .133 + .166*x, [.15,.28] ],
[ x => .075 + .12*x + .813*x**2, [.28,1] ] ] },

rust: { r: [ [ x => 1.556*x, [0,.5] ], [ x => .556 + .444*x, [.5,1] ] ],
g: [ [ x => .742*x, [0,.5] ], [ x => .265 + .208*x, [.5,1] ] ],
b: [ [ x => .191 - .242*x, [0,.5] ], [ x => .105 - .069*x, [.5,1] ] ] },

rainbow2: { r: [ [ x => .471 - 2.566*x, [0,.05] ],
[ x =>.423 - 2.045*x + 6.551*x**2 - 4.092*x**3 , [.05,1] ] ],
g: [ [ x => .107 + .24*x, [0,.07] ],
[ x => -.062 + 2.669*x - 2.012*x**2 - .476*x**4, [.07,1] ] ],
b: [ [ x => .523 + 2.692*x - 6.33*x**2, [0,.4] ],
[ x => 1.212 - 1.534*x, [.4,.55] ], [ x => .919 - .994*x, [.55,.62] ],
[ x => .556 - .421*x, [.62,1] ] ] },

temperature: { r: [ [ x => .176 + 1.633*x, [0,.15] ], [ x => .098 + 2.162*x, [.15,.35] ],
[ x => .092 + 3.098*x - 2.643*x**2, [.35,.67] ],
[ x => 1.362 - .547*x, [.67,1] ] ],
g: [ [ x => .305 + 1.627*x, [0,.4] ], [ x => .739 + .501*x, [.4,.5] ],
[ x => 1 - .018*x, [.5,.67] ], [ x => .185 + 3.688*x - 3.731*x**2, [.67,1] ] ],
b: [ [ x => .928 + .154*x, [0,.42] ], [ x => 1.404 - .985*x, [.42,.5] ],
[ x => 2.014 - 2.205*x, [.5,.58] ], [ x => 2.807 - 3.569*x, [.58,.67] ],
[ x => 1.561 - 1.703*x, [.67,.75] ], [ x => .637 - .473*x, [.75,1] ] ] },

}


var colormaps = Object.assign( {}, matplotlib, mathematica );

0 comments on commit 1126d96

Please sign in to comment.