使用matplotlib生成非重复的连续彩色图

时间:2015-03-08 14:51:02

标签: python matplotlib seaborn

我的目标是创建一个用连续颜色可视化的条形图。 我现在面临的唯一问题是颜色分布在几个条形后重复(见图)。

我希望颜色分布跨越整个x范围。

任何想法如何做到这一点?

enter image description here

1 个答案:

答案 0 :(得分:2)

如果你正在使用matplotlib& seaborn:

import matplotlib.pyplot as plt
import seaborn  as sns
x =  range(10)
y =  range(10)
plt.bar(x,y,color= sns.color_palette("BuGn_r", len(x)))
plt.show()

将x数组的长度作为color_palette()

的第二个参数传递

enter image description here