File Exchange

image thumbnail


version 1.3.0 (15.6 KB) by Konrad
Simple Matlab and python script that import colormaps from matplotlib into Matlab.


Updated 31 Jul 2019

GitHub view license on GitHub
Simple Matlab and python script that import colormaps from matplotlib into Matlab.

getPyPlot_cMap returns any colormap implemented in the matplotlib python library. It calls a python script that writes the colormap matrix into a temporary file, i.e. PYTHON (and the matplotlib module) is REQUIRED. However, the advantage is that you get all the colormaps implemented in matplotlib and that you can specify the number of RGB quantization levels, i.e. the number of colors of the colormap.

A list of colormap names is provided in the function help section. getPyPlot_cMap('!GetNames') returns a cellstring containing all available colormap names. See for an illustration of colormaps.


cMapNames = getPyPlot_cMap('!GetNames')
Returns a cellstring containing all available colormap names.

cMap = getPyPlot_cMap(cMapName)
Returns the colormap cMapName with the default of 128 colors. cMap will be a 128x3 matrix.

cMap = getPyPlot_cMap(cMapName, NumberOfColors)
Specify the number of colors, i.e. the number of rows in cMap.

cMap = getPyPlot_cMap(cMapName, NumberOfColors, keepAlphaChannel)
If keepAlphaChannel is not 0 cMap has a 4th column containing the alpha channel.

cMap = getPyPlot_cMap(cMapName, NumberOfColors, keepAlphaChannel, pythonSystemCommand)
Lets you specify the python command (possibly including a path, see below) used to execute the python script.


If you have python installed but Matlab says 'There was an error executing the command... System returned:...' you can try to pass the path to your python installation explicitly as the 4th parameter, e.g.:

cmp = getPyPlot_cMap('Accent', [], [], '"c:\Program Files\Python37\python.exe"');

Note the double-quotes around the path, which are neccessary because of the containing space character.

Cite As

Konrad (2019). PyColormap4Matlab (, GitHub. Retrieved .

Comments and Ratings (2)


Thanks Piercarlo for letting me know!
I added the solution for this issue to the description above.
If the problem occurs to anyone else: pass the path to your python installtion as the 4th argument.

An error is occurring to me:

"Error using getPyPlot_cMap (line 93)
There was an error executing the command python ...(path)\
System returned:
"python" is not recognized as an internal or external command, or an exe or file batch.
Impossible to find the specified path."

What should I do to fix it?



Fixed issue when path to python script contain white spaces or special characters.
Thanks to Piercarlo!

Updated Description.


List of colormap names (when retrieved with !getNames) is now generated by python script instead of hard-coded in Matlab script.


getNames implemented


Description updated


Image added (taken from

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux