小编Dan*_*llo的帖子

Barplot根据色彩图进行着色?

首先,我对Matplotlib或Seaborn的颜色很新.我的目的是创建一个条形图,其条形图根据自定义调色板着色.这样的东西,但我的自定义调色板(见下面,红色,橙色,绿色和蓝色的调色板):

barplot

我已经使用该LinearSegmentedColormap方法创建了自定义顺序调色板,但我无法在简单中使用它plt.barplot().当然不难,但我看不出路.我使用下面的函数创建了调色板,从这个线程获得:使用matplotlib创建自己的颜色图并绘制颜色比例

def make_colormap(seq):
"""Return a LinearSegmentedColormap
seq: a sequence of floats and RGB-tuples. The floats should be increasing
and in the interval (0,1).
"""
seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
cdict = {'red': [], 'green': [], 'blue': []}
for i, item in enumerate(seq):
    if isinstance(item, float):
        r1, g1, b1 = seq[i - 1]
        r2, g2, b2 = seq[i + 1]
        cdict['red'].append([item, r1, r2])
        cdict['green'].append([item, g1, g2])
        cdict['blue'].append([item, …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib seaborn

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

matplotlib ×1

plot ×1

python ×1

seaborn ×1