Mac OS X
06 09 22 • 23:50&
This post shows step-by-step instructions on importing different classes of colormaps from python (Matplotlib) into Matlab using PyColormap4Matlab.
- Download the PyColormap4Matlab library from the following link: https://www.mathworks.com/matlabcentral/fileexchange/68239-pycolormap4matlab
- Rename the package to PyColormap4Matlab,
- Copy & paste the new folder in your Documents as /Documents/MATLAB/PyColormap4Matlab,
- Open the MATLAB application and link the new folder PyColormap4Matlab to it using the "Home > Set Path" tab in the top menu. Next, click "Add Folder" and select /Documents/MATLAB/PyColormap4Matlab, then click on Open, Save, and Close.
- Install the “Matplotlib" library. To do so, enter the command "
pip3 install matplotlib" in the terminal. For other options, check https://www.geeksforgeeks.org/how-to-install-matplotlib-on-macos/
- Now, you can import the colormaps from Matplotlib to MATLAB. The following MATLAB script imports the colormap Greys from Matplotlib to MATLAB. The name of the new colormap in MATLAB is cl_Greys:
# set the Python path
path_python = '/usr/bin/python3';
# importing Greys colormap from Matplotlib
cl_Greys = getPyPlot_cMap('Greys', , , path_python);
- Hint: to find the Python path (for variable "path_python") enter the "
which python3" command in the terminal.
- For a list of Matplotlib colormaps, check the following link: https://matplotlib.org/stable/tutorials/colors/colormaps.html
- In the following pictures, prepared by Kamyar Mohseni, different classes of Matplotlib colormaps are compared together and also with MATLAB colormaps.