How to create a data-driven colour scheme for a simple line?

Welcome to our Forums Technical Support Support Desk How to create a data-driven colour scheme for a simple line?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #9919
    petercreate
    Participant

      Saying I have a time series of temperature, could I manage to turn the simple black line indicating the change of temperature to a colourful line transiting from blue (cooler) to red (warmer)?

      #9920
      kirkt
      Participant

        Excellent question.  I also would love to hear the answer, but with the slight variation of changing the line color by its Y value, so as to indicate the Y value’s crossing a threshold value (think something like the line is green until it gets above a certain threshold Y value, then it turns yellow, and when it crosses an even higher Y threshold value it turns red).

        I have done this before by using masks and plotting the same data multiple times with the above colors and making a single composite line, but being able to do it with one plot command would be cool.

        Kirk

        • This reply was modified 1 year, 3 months ago by kirkt.
        #9922
        dgteam
        Moderator

          The way to do this is to use a different command – the Connect command.

          There is an example file that I would recommend reviewing called “Line segments with color scheme”.

          LineSegmentsColorSchemes

          The basic approach is that you use an expression to create a second x snd y column that are the values at the next row.  Then the connect command draws the line segments for each row.  You can use any column in the table to base a color scheme.

          Please try it out and let us know if this works for you or if you have any other questions.

          #9923
          petercreate
          Participant

            Thank dgteam. The solution partially solve the issue. The problem is when the line connecting two points is descending or ascending, the colour won’t change with value, which is defined by the starting or ending point.  Therefore, errors occur when the same values have different colours. I attached a shot here.Screenshot 2022-12-01 at 14.50.50

            #9924
            dgteam
            Moderator

              What you can do is use the Plot action column to first interpolate your data to get a denser set of points on the x axis.

              Here is an example to illustrate.  The first two data columns are the original data.

              LineColorRamp

              The Date column in the group is generated using an expression to list each day.  the Value uses this Date as the Locations to interpolate (Plot action column).  The x and y input columns outlined in blue are the original discrete data that we are interpolating.

              LineColorRamp2

              That gives a value for each day and when this is used in the Connect command (using the approach outlined in the example file mentioned in the last post), a smooth representation of the value is shown using the color ramp.

              LineColorRamp3

              Here we used the linear interpolate method (bottom of the Plot action column).  You could also choose a cubic or spline, depending on what makes the most sense for your data.

              Does this help?

              #9926
              petercreate
              Participant

                Yes, this solved this issue completely. Thanks.

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.

              Welcome to our Forums Technical Support Support Desk How to create a data-driven colour scheme for a simple line?