LineCollection中的颜色范围

时间:2013-05-06 18:55:00

标签: matplotlib

我在图像上过度绘制多色线条,线条的颜色应该代表一个给定的参数,它在-1和3之间变化。

以下代码部分是构建这些代码的代码:

            x = self._tprun.r[0,p,::100]  # x coordinate
            y = self._tprun.r[1,p,::100]  # y coordinate

            points = np.array([x, y]).T.reshape(-1, 1, 2)
            segments = np.concatenate([points[:-1], points[1:]], axis=1)

            # 'color' is the parameter that will color the line

            vmin =  self._color[p,:].min()
            vmax =  self._color[p,:].max()

            lc = LineCollection(segments,
                                cmap=plt.get_cmap('jet'),
                                norm=plt.Normalize(vmin=vmin,vmax=vmax))

            lc.set_array(self._color[p,:]) 

            lc.set_linewidth(1)
            self._ax.add_collection(lc)

这段代码在'p'的循环内,所以它会在数组'x'和'y'给出的位置创建几行,颜色应该由'self._color [给出] p,:]”

正如我所说,'_ color [p,:]'大致在-1和3之间变化。以下是'_color [p,:]'的示例:

enter image description here

我的问题是创建的线条看起来没有太多的颜色变化,它们看起来都是单色的深蓝色,而_color [p,:]变化很大,我要求标准化取其最小/最大值

这是一个这样一条线的例子(看看振荡的深蓝色线,其他黑色线是另一个值的轮廓):

enter image description here

这些功能的工作方式是否缺少某些内容?

1 个答案:

答案 0 :(得分:0)

知道了! 问题的答案在这里:

        x = self._tprun.r[0,p,::100]  # re-sample every 100 values !!
        y = self._tprun.r[1,p,::100]  # 

        # [...]

        #lc.set_array(self._color[p,:]) # self._color[p,:] is not resampled
        lc.set_array(self._color[p,::100])  # this works because resampled

意味着'color'数组实际上比用于线段位置的数组大得多....只有'_color'的第一个值才使用,其中值的变化不大。