1. 介绍

最近在写论文的时候,看到其他论文中的云图配色很是喜欢,但是自己使用Origin绘制的时候却找不到这种配色。后来想到Python的Matplotlib库中有很多配色,这些图也有可能是Python绘制的(我确实在里面找到了我想要的颜色图)。下面的问题就是如何把Matplotlib库中的配色转化成Origin的配色格式?

在Google上寻找了一番后,还真找到了一个开源项目就是干这个的,与我的想法不谋而合。

此项目的原作者的博客以及Github页面可以点击查看,本文只是介绍一下此项目以及使用方法。

2. 关于此项目

这个项目是用Python写的,包含GUI界面(界面是tkinter写的),使用起来也比较方便,界面如下:

Python中matplotlib的颜色图导入Origin或者MATLAB(Pal格式)

作者介绍的此项目如下:

  • 程序的用途:

Python的颜色图( colormaps)非常多而且非常好看,在用Origin或者MATLAB的时候自己也想用Python的颜色图,因此写了这样一个程序。

其实已经有一个将MATLAB程序导出为Origin的‘pal’文件的函数cmap2pal,但是我想导出Python的颜色图的话就得先导出一个MATLAB版本的,再将MATLAB导出为‘pal’文件,比较麻烦,因此我‘cmap2pal’做了一点修改,变成了Python版本,并且添加了图像化的界面。具体写的时候一些二进制的输出的问题参见了这个问题的答案:

How to write char and integer into binary files with specificed precison using python?

  • 如何使用

直接打开程序,选取你要输出的颜色图的名字以及是输出到MATLAB还是Origin格式。

图形化的操作多了一个预览操作,你可以提前预览你输出的颜色图的名字

3. Matplotlib中的Colormaps介绍

上面说了这个程序可以根据Matplotlib中的Colormaps的名称进行预览并输出成想要的格式,下面就是关于Matplotlib中的Colormaps的一些名称及分类。

Classes of colormaps

Colormaps are often split into several categories based on their function (see, e.g., [Moreland]):

  1. Sequential: change in lightness and often saturation of color incrementally, often using a single hue; should be used for representing information that has ordering.
  2. Diverging: change in lightness and possibly saturation of two different colors that meet in the middle at an unsaturated color; should be used when the information being plotted has a critical middle value, such as topography or when the data deviates around zero.
  3. Cyclic: change in lightness of two different colors that meet in the middle and beginning/end at an unsaturated color; should be used for values that wrap around at the endpoints, such as phase angle, wind direction, or time of day.
  4. Qualitative: often are miscellaneous colors; should be used to represent information which does not have ordering or relationships.

Sequential

plot_color_gradients('Perceptually Uniform Sequential',
                     ['viridis', 'plasma', 'inferno', 'magma', 'cividis'])

Matplotlib中的Colormaps

plot_color_gradients('Sequential',
                     ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
                      'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                      'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'])

Matplotlib中的Colormaps

Sequential2

plot_color_gradients('Sequential (2)',
                     ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone',
                      'pink', 'spring', 'summer', 'autumn', 'winter', 'cool',
                      'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper'])

Matplotlib中的Colormaps

Diverging

plot_color_gradients('Diverging',
                     ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu',
                      'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic'])

Matplotlib中的Colormaps

Cyclic

plot_color_gradients('Cyclic', ['twilight', 'twilight_shifted', 'hsv'])

Matplotlib中的Colormaps

Qualitative

plot_color_gradients('Qualitative',
                     ['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
                      'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
                      'tab20c'])

Matplotlib中的Colormaps

Miscellaneous

plot_color_gradients('Miscellaneous',
                     ['flag', 'prism', 'ocean', 'gist_earth', 'terrain',
                      'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap',
                      'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet',
                      'turbo', 'nipy_spectral', 'gist_ncar'])

plt.show()

Matplotlib中的Colormaps

4. 导入Origin使用

生成的 .*pal 文件可以放在Origin的 Palettes 文件夹中,路径如下:

(或者在Origin软件中打开:帮助 → 打开文件夹 → 程序文件夹 → Palettes

Python中matplotlib的颜色图导入Origin或者MATLAB(Pal格式)

比如我导入了名为 matplotlib_Jet.pal 的文件到上述文件夹内,如何在云图中使用导入的配色可以参考以下步骤:

Python中matplotlib的颜色图导入Origin或者MATLAB(Pal格式)

如果打不开Github可以使用以下网盘的分享链接:
链接:https://pan.baidu.com/s/1mea5JfzdCQtID-N2j692Xw
提取码:pyor


长风破浪会有时,直挂云帆济沧海。