2

I'm overplotting multicolored lines on an image, the color of the lines is supposed to represent a given parameter that varies between roughtly -1 and 3.

The following portion of code is the one that builds these lines :

            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)

This code is inside a loop on 'p' and so it will create several lines at locations given by the arrays 'x' and 'y' and for which the color should be given by the value of 'self._color[p,:]'.

As I said, '_color[p,:]' roughly varies between -1 and 3. Here is an example of what '_color[p,:]' may be :

enter image description here

My problem is that the lines that are created appear without much variation of the color, they all look kind of monochrome dark blue whereas _color[p,:] varies much and I ask for the normalization to take its min/max values.

here is an example of such a line (look at the oscillating dark blue line, other black lines are a contour of another value) :

enter image description here

Is there something I'm missing in the way these functions work?

tm8cc
  • 1,111
  • 2
  • 12
  • 26

1 Answers1

1

Got it! Answer to the question is here :

        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

meaning that the 'color' array was actually much larger than the arrays used for position of the line segments.... only the first values of '_color' where used where its values do not vary that much.

tm8cc
  • 1,111
  • 2
  • 12
  • 26
  • glad you figured it out! Please remember to accept your answer (and update it to actually fix the problem;) ) when it will let you – tacaswell May 06 '13 at 19:44
  • what do you mean by "accept your answer" and "update it to fix the problem"? – tm8cc May 06 '13 at 20:54
  • "accept answer" is click on the big gray check box, and the code in your answer is just a copy of the code that you say does not work. You should update it to re-sample the color data. – tacaswell May 06 '13 at 21:01
  • @Heimdall You should also try marking some of the other answers people have provided for you as "accepted" too. As of now, you have 14 questions and you've only accepted this one! – Hooked May 10 '13 at 18:18
  • yeah I'll do that thanks! I wasn't really aware of how things work around here. – tm8cc May 10 '13 at 22:13