Function Repository Resource:

AddMatplotlibColors

Source Notebook

Add Matplotlib colormaps to ColorData

Contributed by: Jason Biggs and Nikolay Murzin

ResourceFunction["AddMatplotlibColors"][]

adds Matplotlib colormaps for use with graphics primitives and functions.

Details

These are the mpl colormaps by Nathaniel Smith and Stefan van der Walt used by Matplotlib:
Magma
Inferno
Plasma
Viridis
EricsRdBuGnYl
EricsRdBuGnYl2
EricsPuBuGnYl
FakeParula
JoesBluGrnPnk2

Examples

Basic Examples (2) 

Add Matplotlib colormaps:

In[1]:=
ResourceFunction["AddMatplotlibColors"][]
Out[1]=

Get the colormap by its name:

In[2]:=
ColorData /@ ResourceFunction["AddMatplotlibColors"][]
Out[2]=
In[3]:=
gradient[name_] := DensityPlot[x, {x, -1, 1}, {y, 0, 1}, FrameTicks -> None, AspectRatio -> 1/10, PlotRange -> All, ColorFunction -> name, PlotPoints -> 40, PlotRangePadding -> None, ImageSize -> 200]

gradient["Magma"]
Out[3]=

Applications (1) 

Use them like the built-in color functions:

In[4]:=
ResourceFunction["AddMatplotlibColors"][];
In[5]:=
DensityPlot[Sin[x - y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "Viridis"]
Out[5]=

Neat Examples (1) 

A gallery of colormaps:

In[6]:=
showcolorfunction[name_] := With[{opts = {PlotRange -> All, ColorFunction -> name, PlotPoints -> 40, PlotRangePadding -> None, ImageSize -> 200}}, Column[{name, DensityPlot[
     Cos[x] Sin[y], {x, -2 \[Pi], 2 \[Pi]}, {y, -\[Pi], \[Pi]}, FrameTicks -> None, AspectRatio -> 1/4, opts], DensityPlot[
     10 Cos[x^2] Exp[y], {x, -2 \[Pi], 2 \[Pi]}, {y, -\[Pi], 0}, FrameTicks -> None, AspectRatio -> 1/2, opts], DensityPlot[x, {x, -1, 1}, {y, 0, 1}, FrameTicks -> {{None, None}, {Automatic, None}}, AspectRatio -> 1/10, opts]}, Center, 0]]
Grid@Partition[
  showcolorfunction /@ ResourceFunction["AddMatplotlibColors"][], 3]
Out[6]=

Version History

  • 1.0.0 – 22 October 2021

Related Resources

License Information