matplotlib:基于强度的stackplot中的colorspectrum

时间:2017-08-11 19:34:27

标签: python matplotlib

民间, 我有矢量[2,3,5,8,4,3,2,1],我在y轴上绘制范围(10)作为x轴。我正在使用matplotlib的stackplot这样做。

import matplotlib.pyplot as plt

y = [1, 3, 4, 5, 6, 7, 8, 6]
x = range(8)

fig, ax = plt.subplots()
ax.stackplot(x, y)

plt.show()

现在我有另一个向量[8,9,0,0,0,0,1,4],它是向量y的强度。我需要使用这个强度矢量来对我的堆栈图进行颜色编码,以便我可以看到颜色光谱。强度超过10.我该怎么做?

1 个答案:

答案 0 :(得分:1)

我做了一些酒吧情节,这是你想要的吗? enter image description here

相应的代码如下

import matplotlib.pyplot as plt                                                    
import numpy as np                                                                 

y = [1, 3, 4, 5, 6, 7, 8, 6]                                                       
x = range(len(y))                                                                  

y2 = np.array([8, 9, 0, 0, 0, 0, 1, 4]) / 10.0                                     

fig, ax = plt.subplots()                                                           
ax.bar(x, y, color=map(str, y2))                                                   

plt.show()