Creating a multi-colored or multi-thickness line?

Discussion in 'MATLAB' started by Stu, Sep 9, 2009.

  1. Stu

    Stu Guest

    Hi all,

    I am trying to find a way to display a line that has varying colors or linewidths based on some categorical data. The values to be plotted are in the 100-500 range, plotted versus time (datenum format). There are 3 categories for the data that should be plotted as thin/medium/thick or red/yellow/green, etc. More detail below.

    The data are value versus non-uniformly-spaced time. I am plotting both the raw points and several moving averages. The points (t,y) pairs are plotted as 'k.' as a line object. For the running averages, I have a sliding window that looks backwards a specified number of hours. I can count exactly how many samples are included in each point of the sliding window, and using this I have classified each point of the moving average vector in another vector, values (categories) from 1:3 (category 1: no samples, all interpolated; category 2: 1 to 3 samples; category 3: more than 3 samples). I want the color and/or thickness of the line for the moving average to change, in order to indicate how many samples comprise each point.

    One thought is to make separate line objects for each segment of data between which there are category changes. I would prefer not to do this though, as a single object containing the full moving average data is desirable. I have thought about creating the moving average not as a line but rather a patch object, and then using the FaceVertexCData to store the categories for each point. From there I can use flat or interp color, but still can't do anything about the linewidth.

    If I go this "patch" route, can someone please tell me which would be more efficient: to create a "face" for every pair of points ([1:2;2:3;3:4;4:5; ... ;(end-1):end]) or instead to create a "face" only for those segments of like category ([1:14;14:16;16:22] ; % and fill in the appropriate required zeros for a rectangular matrix)? And is there a way to change linewidth or linestyle for different edges of a patch object?

    Or, is there a better way to get my desired result?

    Thanks in advance,
    Stu
     
    Stu, Sep 9, 2009
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.